Skip to content

Commit

Permalink
Merge pull request #414 from ydah/parameterizing-result-meets-named-r…
Browse files Browse the repository at this point in the history
…efs-aliased

Add support for Named Reference in parameterizing rules callers
  • Loading branch information
yui-knk authored May 27, 2024
2 parents bc2f0b4 + effe94a commit 4a07a4f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 68 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
4 changes: 3 additions & 1 deletion spec/fixtures/integration/parameterizing_rules.y
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ static int yyerror(YYLTYPE *loc, const char *str);

%union {
int num;
char* str;
}

%token <num> ODD EVEN

%type <num> stmt
%type <str> opt_nl

%%

Expand All @@ -33,7 +35,7 @@ stmt: ODD opt_nl { printf("odd: %d\n", $1); }
| EVEN opt_semicolon { printf("even: %d\n", $1); }
;

opt_nl: '\n'?
opt_nl: '\n'?[nl] <str> { $$ = $nl; }
;

opt_semicolon: semicolon?
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 4a07a4f

Please sign in to comment.