Skip to content

Commit b662379

Browse files
authored
Merge pull request #405 from ydah/nested-with-tag
Add support nested parameterizing rules with tag
2 parents 595472f + e4ff1f2 commit b662379

File tree

4 files changed

+234
-80
lines changed

4 files changed

+234
-80
lines changed

lib/lrama/parser.rb

Lines changed: 78 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ rule
282282
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]])
283283
result = builder
284284
}
285-
| rule_rhs IDENTIFIER "(" parameterizing_args ")"
285+
| rule_rhs IDENTIFIER "(" parameterizing_args ")" tag_opt
286286
{
287287
builder = val[0]
288-
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3])
288+
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
289289
result = builder
290290
}
291291
| rule_rhs "{"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* This is comment for this file.
3+
*/
4+
5+
%{
6+
// Prologue
7+
static int yylex(YYSTYPE *val, YYLTYPE *loc);
8+
static int yyerror(YYLTYPE *loc, const char *str);
9+
%}
10+
11+
%union {
12+
int i;
13+
}
14+
15+
%token <i> number
16+
17+
%rule nested_nested_option(X): /* empty */
18+
| X
19+
;
20+
21+
%rule nested_option(X): /* empty */
22+
| nested_nested_option(X) <i>
23+
;
24+
25+
%rule option(Y): /* empty */
26+
| nested_option(Y) <i>
27+
;
28+
29+
%%
30+
31+
program : option(number) <i>
32+
;
33+
34+
%%
35+
36+
static int yylex(YYSTYPE *yylval, YYLTYPE *loc)
37+
{
38+
return 0;
39+
}
40+
41+
static int yyerror(YYLTYPE *loc, const char *str)
42+
{
43+
return 0;
44+
}
45+
46+
int main(int argc, char *argv[])
47+
{
48+
}

0 commit comments

Comments
 (0)