diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-10-07 17:33:40 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-10-07 17:45:20 +0200 |
| commit | 12e304fd56f054ba7296ab538eecd4280a67832a (patch) | |
| tree | 218f37dc04fa14323d2ca7704e47a830dcd98b22 /boot/parser.yy | |
| parent | f547dae96d770cc7bc27d3790d0d87bb8e37963d (diff) | |
| download | elna-12e304fd56f054ba7296ab538eecd4280a67832a.tar.gz | |
Allow assigning contants to enumeration members
Diffstat (limited to 'boot/parser.yy')
| -rw-r--r-- | boot/parser.yy | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/boot/parser.yy b/boot/parser.yy index 04c07a8..e8c3590 100644 --- a/boot/parser.yy +++ b/boot/parser.yy @@ -162,6 +162,8 @@ along with GCC; see the file COPYING3. If not see %type <std::vector<elna::boot::attribute>> attributes; %type <std::vector<std::string>> import_declaration; %type <std::vector<elna::boot::identifier>> required_identifiers optional_identifiers generic_parameters; +%type <std::unique_ptr<elna::boot::enumeration_type_expression::member_declaration>> enumeration_member; +%type <std::vector<elna::boot::enumeration_type_expression::member_declaration>> enumeration_members; %type <elna::boot::named_expression *> name_reference; %type <std::vector<elna::boot::import_declaration *>> import_declarations; %type <elna::boot::array_type_expression *> array_type_expression; @@ -679,9 +681,24 @@ type_expression: } | "proc" procedure_heading { $$ = $2; } - | "(" required_identifiers ")" - { $$ = new boot::enumeration_type_expression(boot::make_position(@$), $2); } + | "(" enumeration_members ")" + { $$ = new boot::enumeration_type_expression(boot::make_position(@$), std::move($2)); } | name_reference { $$ = $1; } +enumeration_members: + enumeration_member "," enumeration_members + { + $$ = std::move($3); + $$.emplace($$.cbegin(), std::move(*$1)); + } + | enumeration_member { $$.emplace_back(std::move(*$1)); } +enumeration_member: + identifier + { $$ = std::make_unique<boot::enumeration_type_expression::member_declaration>(std::move(*$1), nullptr); } + | identifier "=" expression + { + $$ = std::make_unique<boot::enumeration_type_expression::member_declaration>(std::move(*$1), + std::unique_ptr<boot::expression>($3)); + } generic_parameters: %empty {} | "#[" required_identifiers "]" { $$ = $2; } |
