Skip to content

Commit

Permalink
Merge pull request #405 from ydah/nested-with-tag
Browse files Browse the repository at this point in the history
Add support nested parameterizing rules with tag
  • Loading branch information
yui-knk authored Apr 29, 2024
2 parents 595472f + e4ff1f2 commit b662379
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 80 deletions.
156 changes: 78 additions & 78 deletions lib/lrama/parser.rb

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

4 changes: 2 additions & 2 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ rule
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], location: @lexer.location, args: [val[1]])
result = builder
}
| rule_rhs IDENTIFIER "(" parameterizing_args ")"
| rule_rhs IDENTIFIER "(" parameterizing_args ")" tag_opt
{
builder = val[0]
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3])
builder.symbols << Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[3], lhs_tag: val[5])
result = builder
}
| rule_rhs "{"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This is comment for this file.
*/

%{
// Prologue
static int yylex(YYSTYPE *val, YYLTYPE *loc);
static int yyerror(YYLTYPE *loc, const char *str);
%}

%union {
int i;
}

%token <i> number

%rule nested_nested_option(X): /* empty */
| X
;

%rule nested_option(X): /* empty */
| nested_nested_option(X) <i>
;

%rule option(Y): /* empty */
| nested_option(Y) <i>
;

%%

program : option(number) <i>
;

%%

static int yylex(YYSTYPE *yylval, YYLTYPE *loc)
{
return 0;
}

static int yyerror(YYLTYPE *loc, const char *str)
{
return 0;
}

int main(int argc, char *argv[])
{
}
Loading

0 comments on commit b662379

Please sign in to comment.