enum base case parsing api passed

This commit is contained in:
Edward R. Gonzalez 2023-07-08 19:13:52 -04:00
parent a8e03aa7ba
commit 41f0e49cb0
2 changed files with 30 additions and 7 deletions

View File

@ -391,7 +391,7 @@ namespace gen
); );
} }
result.append_fmt( "%s};" result.append_fmt( "%s};\n"
, body()->to_string() , body()->to_string()
); );
} }
@ -3207,6 +3207,12 @@ namespace gen
{ {
return Arr[Idx]; return Arr[Idx];
} }
inline
Token& previous()
{
return Arr[Idx - 1];
}
}; };
TokArray lex( StrC content ) TokArray lex( StrC content )
@ -3651,6 +3657,7 @@ namespace gen
} }
# define currtok toks.current() # define currtok toks.current()
# define prevtok toks.previous()
# define eat( Type_ ) toks.__eat( Type_, context ) # define eat( Type_ ) toks.__eat( Type_, context )
# define left ( array_count(toks.Arr) - toks.Idx ) # define left ( array_count(toks.Arr) - toks.Idx )
@ -4294,12 +4301,29 @@ namespace gen
while ( currtok.Type != TokType::BraceCurly_Close ) while ( currtok.Type != TokType::BraceCurly_Close )
{ {
body.Length += currtok.Length; eat( TokType::Identifier);
eat( currtok.Type ); if ( currtok.Type == TokType::Operator && currtok.Text[0] == '=' )
{
eat( TokType::Operator );
while ( currtok.Type != TokType::Comma || currtok.Type != TokType::BraceCurly_Close )
{
eat( currtok.Type );
}
}
if ( currtok.Type == TokType::Comma )
{
eat( TokType::Comma );
}
} }
body.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body.Text;
eat( TokType::BraceCurly_Close ); eat( TokType::BraceCurly_Close );
eat( TokType::Statement_End );
} }
else else
{ {
@ -4313,9 +4337,9 @@ namespace gen
if ( body.Length ) if ( body.Length )
{ {
mem_copy( entries_code, body.Text, body.Length ); // mem_copy( entries_code, body.Text, body.Length );
Code untyped_body = untyped_str( { entries_length, entries_code } ); Code untyped_body = untyped_str( body );
result->Type = is_enum_class ? Enum_Class : Enum; result->Type = is_enum_class ? Enum_Class : Enum;
result->add_entry( untyped_body ); result->add_entry( untyped_body );

View File

@ -45,7 +45,6 @@ void gen_sanity()
gen_sanity_file.print_fmt("\n"); gen_sanity_file.print_fmt("\n");
// Enum // Enum
if (0)
{ {
Code fwd = parse_enum( code( Code fwd = parse_enum( code(
enum ETestEnum : u8; enum ETestEnum : u8;
@ -61,7 +60,7 @@ void gen_sanity()
)); ));
Code fwd_enum_class = parse_enum( code( Code fwd_enum_class = parse_enum( code(
enum class ETestEnum : u8; enum class ETestEnumClass : u8;
)); ));
gen_sanity_file.print(fwd); gen_sanity_file.print(fwd);