Skip to content

Commit

Permalink
Add support for Named Reference in parameterizing rules callers
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed May 22, 2024
1 parent a7638d0 commit 5e86b03
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 67 deletions.
126 changes: 64 additions & 62 deletions lib/lrama/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,17 @@ rule
builder.add_rhs(token)
result = builder
}
| rhs symbol parameterizing_suffix TAG?
| rhs symbol parameterizing_suffix named_ref_opt TAG?
{
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]], lhs_tag: val[3])
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], alias_name: val[3], location: @lexer.location, args: [val[1]], lhs_tag: val[4])
builder = val[0]
builder.add_rhs(token)
builder.line = val[1].first_line
result = builder
}
| rhs IDENTIFIER "(" parameterizing_args ")" TAG?
| rhs IDENTIFIER "(" parameterizing_args ")" named_ref_opt TAG?
{
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6])
builder = val[0]
builder.add_rhs(token)
builder.line = val[1].first_line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ stmts: separated_list(';', stmt)
;

stmt: pair(ODD, EVEN) <num> { printf("pair odd even: %d\n", $1); }
| pair(EVEN, ODD) <num> { printf("pair even odd: %d\n", $1); }
| pair(EVEN, ODD)[result] <num> { printf("pair even odd: %d\n", $result); }
;

%%
Expand Down

0 comments on commit 5e86b03

Please sign in to comment.