Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum now supports lack of commas #1447

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions examples/test/misc/hello_new_syntax.das
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,40 @@ enum EmptyEnum {
}

enum MyEnum {
ONE,
TWO,
ONE
TWO
THREE
}

enum EnumWithTrailingComma {
ONE,
TWO,
ONE
TWO
}

enum Enum8u : uint8 {
ONE,
TWO,
ONE
TWO
THREE = 16u8 // TODO: 16i8 causes 2x smart_ptr_leak, note - it causes 1x smart_ptr_leak with old parser
}

enum private Enum64 : uint64 { // 64 bit enum, private
ONE,
TWO,
ONE
TWO
THREE = 16ul
}

enum WhiteSpaceEnum {

ONE
TWO,,,,,,

THREE

FOUR = 4
,

}

// TODO: add example of enum with annotation. for now we don't have a builtin enum one

[export]
Expand Down
28 changes: 20 additions & 8 deletions examples/test/misc/hello_world.das
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,40 @@ enum EmptyEnum {
}

enum MyEnum {
ONE,
TWO,
ONE
TWO
THREE
}

enum EnumWithTrailingComma {
ONE,
TWO,
ONE
TWO
}

enum Enum8u : uint8 {
ONE,
TWO,
ONE
TWO
THREE = 16u8 // TODO: 16i8 causes 2x smart_ptr_leak, note - it causes 1x smart_ptr_leak with old parser
}

enum private Enum64 : uint64 { // 64 bit enum, private
ONE,
TWO,
ONE
TWO
THREE = 16ul
}

enum WhiteSpaceEnum {

ONE
TWO,,,,,,

THREE

FOUR = 4
,

}

// TODO: add example of enum with annotation. for now we don't have a builtin enum one

[export]
Expand Down
8 changes: 4 additions & 4 deletions src/parser/ds2_lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3115,18 +3115,18 @@ YY_RULE_SETUP
YYCOLUMN(yyextra->das_yycolumn = 0, "NEW LINE (with tail end)");
das_accept_cpp_comment(yyextra->g_CommentReaders, yyscanner, *yylloc_param, yytext);
#ifdef FLEX_DEBUG
printf("indent:%i parentheses:%i squares:%i keyword:%s\n",
yyextra->das_indent_level, yyextra->das_nested_parentheses, yyextra->das_nested_square_braces,
printf("char:%c indent:%i parentheses:%i squares:%i keyword:%s\n",
yyextra->das_indent_char, yyextra->das_indent_level, yyextra->das_nested_parentheses, yyextra->das_nested_square_braces,
yyextra->das_keyword ? "true" : "false");
#endif
if ( yyextra->das_indent_level && !yyextra->das_keyword ) {
if ( !yyextra->das_nested_parentheses && !yyextra->das_nested_square_braces ) {
// here, we may need to emit ; if we are in a block
// yyextra->das_nested_curly_braces is set, but we need to know if we are in the emit block
#ifdef FLEX_DEBUG
printf("emit ; at EOL, line %i\n", yylineno);
printf("emit %c at EOL, line %i\n", yyextra->das_indent_char, yylineno);
#endif
return ';';
return yyextra->das_indent_char;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/parser/ds2_lexer.lpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,18 +702,18 @@ void das_accept_cpp_comment ( vector<CommentReader *> & crdi, yyscan_t scanner,
YYCOLUMN(yyextra->das_yycolumn = 0, "NEW LINE (with tail end)");
das_accept_cpp_comment(yyextra->g_CommentReaders, yyscanner, *yylloc_param, yytext);
#ifdef FLEX_DEBUG
printf("indent:%i parentheses:%i squares:%i keyword:%s\n",
yyextra->das_indent_level, yyextra->das_nested_parentheses, yyextra->das_nested_square_braces,
printf("char:%c indent:%i parentheses:%i squares:%i keyword:%s\n",
yyextra->das_indent_char, yyextra->das_indent_level, yyextra->das_nested_parentheses, yyextra->das_nested_square_braces,
yyextra->das_keyword ? "true" : "false");
#endif
if ( yyextra->das_indent_level && !yyextra->das_keyword ) {
if ( !yyextra->das_nested_parentheses && !yyextra->das_nested_square_braces ) {
// here, we may need to emit ; if we are in a block
// yyextra->das_nested_curly_braces is set, but we need to know if we are in the emit block
#ifdef FLEX_DEBUG
printf("emit ; at EOL, line %i\n", yylineno);
printf("emit %c at EOL, line %i\n", yyextra->das_indent_char, yylineno);
#endif
return ';';
return yyextra->das_indent_char;
}
}
}
Expand Down
Loading
Loading