aboutsummaryrefslogtreecommitdiff
path: root/boot/parser.yy
diff options
context:
space:
mode:
Diffstat (limited to 'boot/parser.yy')
-rw-r--r--boot/parser.yy48
1 files changed, 16 insertions, 32 deletions
diff --git a/boot/parser.yy b/boot/parser.yy
index 21ff827..cc0a46c 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -88,7 +88,7 @@ along with GCC; see the file COPYING3. If not see
%token <std::string> STRING
%token <bool> BOOLEAN
%token LEFT_PAREN "(" RIGHT_PAREN ")" LEFT_SQUARE "[" RIGHT_SQUARE "]"
- LEFT_BRACE "{" RIGHT_BRACE "}" GENERIC_OPEN "#["
+ LEFT_BRACE "{" RIGHT_BRACE "}" GENERIC_OPEN "#[" ATTRIBUTE_OPEN "#{"
%token ASSIGNMENT ":="
EXCLAMATION "!" ARROW "->"
AT "@" HAT "^"
@@ -190,9 +190,9 @@ identifier_definition:
IDENTIFIER "*" { $$ = std::make_unique<boot::identifier_definition>($1, boot::make_position(@1), true); }
| IDENTIFIER { $$ = std::make_unique<boot::identifier_definition>($1, boot::make_position(@1), false); }
attribute:
- TRAIT "(" required_expressions ")"
+ "#{" IDENTIFIER optional_expressions "}"
{
- $$ = std::make_unique<boot::attribute>(boot::identifier($1, boot::make_position(@1)), $3);
+ $$ = std::make_unique<boot::attribute>(boot::identifier($2, boot::make_position(@2)), $3);
}
attributes:
%empty {}
@@ -202,17 +202,10 @@ attributes:
$$.emplace($$.cbegin(), std::move(*$1));
}
attributed_identifier:
- attributes identifier_definition
+ identifier_definition attributes
{
- $$ = $2;
- $$->attributes = $1;
-
- // An empty rule is located where the previous token ended, which
- // would push the declaration's position back over it.
- if ($$->attributes.empty())
- {
- @$ = @2;
- }
+ $$ = $1;
+ $$->attributes = $2;
}
identifier_definitions:
attributed_identifier "," identifier_definitions
@@ -225,8 +218,11 @@ return_declaration:
%empty {}
| "->" "!" { $$ = boot::procedure_type_expression::return_t(std::monostate{}); }
| "->" type_expression { $$ = boot::procedure_type_expression::return_t($2); }
-procedure_heading: "(" field_declarations ")" return_declaration
- { $$ = std::make_unique<boot::procedure_type_expression>(boot::make_position(@$), $2, $4); }
+procedure_heading: "(" field_declarations ")" attributes return_declaration
+ {
+ $$ = std::make_unique<boot::procedure_type_expression>(boot::make_position(@$), $2, $5);
+ $$->attributes = $4;
+ }
procedure_declaration:
"proc" identifier_definition generic_parameters procedure_heading procedure_body
{
@@ -616,33 +612,21 @@ type_expression:
{
$$ = new boot::pointer_type_expression(boot::make_position(@$), $2);
}
- | attributes "record" field_declarations "end"
+ | "record" attributes field_declarations "end"
{
- std::vector<boot::attribute> written = $1;
-
- if (written.empty())
- {
- @$ = @2 + @4;
- }
auto *record = new boot::record_type_expression(boot::make_position(@$), $3);
- record->attributes = std::move(written);
+ record->attributes = $2;
$$ = record;
}
- | attributes "record" "(" name_reference ")" field_declarations "end"
+ | "record" "(" name_reference ")" attributes field_declarations "end"
{
- std::vector<boot::attribute> written = $1;
-
- if (written.empty())
- {
- @$ = @2 + @7;
- }
- boot::named_expression *reference = $4;
+ boot::named_expression *reference = $3;
auto *record = new boot::record_type_expression(boot::make_position(@$), $6,
boot::identifier(reference->name, reference->position()),
std::move(reference->arguments));
- record->attributes = std::move(written);
+ record->attributes = $5;
delete reference;
$$ = record;
}