Removed GEN_FEATURE_PARSING macro, fixes to readme

Parsing constructors are too ergonomic to be a "optional" feature.
This commit is contained in:
2023-07-19 00:14:15 -04:00
parent 4d2f6a6315
commit db584d8fe6
8 changed files with 85 additions and 98 deletions

View File

@ -6,17 +6,16 @@ All the library code is contained in two files: `gen.hpp` and `gen.cpp`
Feature Macros:
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
* `GEN_ENFORCE_STRONG_CODE_TYPES` : Enforces casts to filtered code types.
* `GEN_FEATURE_PARSING` : Defines the parse constructors
* `GEN_FEATURE_EDITOR` : Defines the file editing features for changing definitions based on ASTs
* `GEN_FEATURE_SCANNER` : Defines the file scanning features for generating ASTs
`GEN_USE_RECURSIVE_AST_DUPLICATION` is available but its not well tested and should not need to be used.
If constructing ASTs properly. There should be no modification of ASTs, and thus this would never become an issue.
(I will probably remove down the line...)
Due to the design of `gen.hpp` to support being written alongside runtime intended code (in the same file), all the code is wrapped in a `gen_time` `#ifdef` and then wrapped further in a `gen` namespace to avoid pollution of the global scope.
Due to the design of `gen.hpp` to support being written alongside runtime intended code (in the same file), all the code is wrapped in a `GEN_TIME` `#ifdef` and then wrapped further in a `gen` namespace to avoid pollution of the global scope.
*Note: Its possible with the scanner feature to support parsing runtime files that use "generic" macros or identifiers with certain patterns.
This can be used to auto-queue generation of dependent definitions for the symbols used.*
@ -30,27 +29,27 @@ log_failure definition : based on whether to always use fatal on all errors
Major enum definitions and their associated functions used with the AST data
* `ECode` : Used to tag ASTs by their type
* `EOperator` : Used to tag operator overloads with thier op type
* `EOperator` : Used to tag operator overloads with their op type
* `ESpecifier` : Used with specifier ASTs for all specifiers the user may tag an associated
AST with.
* `AccessSpec` : Used with class and struct ASTs to denote the public, protected, or private fields.
* `EnumT` : Used with def_enum to determine if constructing a regular enum or an enum class.
* `ModuleFlag` : Used with any valid definition that can have export or import related keywords assoicated with it.
* `ModuleFlag` : Used with any valid definition that can have export or import related keywords associated with it.
#### Data Structures
`StringCache` : Hash table for cached strings. (`StringCached` typedef used to denote strings managed by it)
`Code` : Wrapper for `AST` with functionality for handling it appropriately.
`AST` : The node data strucuture for the code.
`AST` : The node data structure for the code.
`Code Types` : Codes with typed ASTs. Body, Param, and Specifier have unique implementation, the rest use `Define_CodeType`
`AST Types` : Filtered AST definitions.
#### Gen Interface
First set of fowards are either backend functions used for various aspects of AST generation or configurating allocators used for different containers.
First set of forwards are either backend functions used for various aspects of AST generation or configurations allocators used for different containers.
Interface fowards defined in order of: Upfront, Parsing, Untyped.
Interface forwards defined in order of: Upfront, Parsing, Untyped.
From there forwards for the File handlers are defined: Builder, Editor, Scanner.

View File

@ -1313,9 +1313,7 @@ namespace gen
CodePools.append( code_pool );
#ifdef GEN_FEATURE_PARSING
LexArena = Arena::init_from_allocator( Allocator_Lexer, LexAllocator_Size );
#endif
Arena string_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
@ -3300,14 +3298,12 @@ namespace gen
#pragma endregion Upfront Constructors
#pragma region Parsing Constructors
#ifdef GEN_FEATURE_PARSING
/*
These constructors are the most implementation intensive other than the edtior or scanner.
These constructors are the most implementation intensive other than the editor or scanner.
*/
namespace Parser
{
/*
This is a simple lexer that focuses on tokenizing only tokens relevant to the library.
It will not be capable of lexing C++ code with unsupported features.
@ -6342,8 +6338,6 @@ namespace gen
# undef curr_tok
# undef eat
# undef left
// End GEN_FEATURE_PARSING
#endif
#pragma endregion Parsing Constructors
#pragma region Untyped Constructors

View File

@ -1458,7 +1458,6 @@ CodeBody def_union_body ( s32 num, Code* codes );
#pragma endregion Upfront
#pragma region Parsing
# ifdef GEN_FEATURE_PARSING
CodeClass parse_class ( StrC class_def );
CodeEnum parse_enum ( StrC enum_def );
CodeBody parse_export_body ( StrC export_def );
@ -1476,7 +1475,6 @@ CodeTypedef parse_typedef ( StrC typedef_def );
CodeUnion parse_union ( StrC union_def );
CodeUsing parse_using ( StrC using_def );
CodeVar parse_variable ( StrC var_def );
#endif
#pragma endregion Parsing
#pragma region Untyped text
@ -1931,6 +1929,27 @@ namespace gen
}
#pragma endregion Constants
#pragma region Macros
# define gen_main main
# define __ NoCode
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
// Same as name just used to indicate intention of literal for code instead of names.
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
# define code_str( ... ) gen::untyped_str( code( __VA_ARGS__ ) )
# define code_fmt( ... ) gen::untyped_str( token_fmt( __VA_ARGS__ ) )
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
# define token_fmt( ... ) gen::token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
#pragma endregion Macros
#ifdef GEN_EXPOSE_BACKEND
namespace gen
{
@ -1953,25 +1972,4 @@ namespace gen
}
#endif
#pragma region Macros
# define gen_main main
# define __ NoCode
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
// Same as name just used to indicate intention of literal for code instead of names.
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
# define code_str( ... ) gen::untyped_str( code( __VA_ARGS__ ) )
# define code_fmt( ... ) gen::untyped_str( token_fmt( __VA_ARGS__ ) )
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
# define token_fmt( ... ) gen::token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
#pragma endregion Macros
#include "gen.pop_ignores.inline.hpp"

View File

@ -1,4 +1,4 @@
#if gen_time
#if GEN_TIME
// This undefines the macros used by the gen library but are not necessary for the user.
#undef GEN_ARCH_64_BIT
@ -66,11 +66,15 @@
#undef stringize_va
#undef txt_StrC
#undef __
#undef args
#undef GEN_TIME
#undef gen_main
#undef gen_time
#undef __
#undef name
#undef code
#undef args
#undef code_str
#undef code_fmt
#undef token_fmt
// gen_time
// GEN_TIME
#endif