diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-12-05 02:55:39 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-12-05 02:55:39 +0900 |
| commit | 43512cc7bdb4949a24e310aa03e67a95c59b5f1b (patch) | |
| tree | 15b872b78a23d748fb22154748559c82ad02d006 | |
| parent | ac561a52f583ce154a27622642a37a7a386cbcd9 (diff) | |
| download | mruby-43512cc7bdb4949a24e310aa03e67a95c59b5f1b.tar.gz mruby-43512cc7bdb4949a24e310aa03e67a95c59b5f1b.zip | |
Reorganize heredoc rules; fix #3273
The following codes used to be SyntaxError:
(1)
a = <<-EOD;
hello
EOD
(2)
<<-EOD.bla begin
k
EOD
end
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 19cb88e5b..05b948f8e 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -1918,7 +1918,7 @@ aref_args : none $$ = $1; NODE_LINENO($$, $1); } - | args ',' assocs trailer + | args comma assocs trailer { $$ = push($1, new_hash(p, $3)); } @@ -1958,7 +1958,7 @@ opt_call_args : none $$ = cons($1,0); NODE_LINENO($$, $1); } - | args ',' assocs ',' + | args comma assocs ',' { $$ = cons(push($1, new_hash(p, $3)), 0); NODE_LINENO($$, $1); @@ -1985,7 +1985,7 @@ call_args : command $$ = cons(list1(new_hash(p, $1)), $2); NODE_LINENO($$, $1); } - | args ',' assocs opt_block_arg + | args comma assocs opt_block_arg { $$ = cons(push($1, new_hash(p, $3)), $4); NODE_LINENO($$, $1); @@ -2014,7 +2014,7 @@ block_arg : tAMPER arg } ; -opt_block_arg : ',' block_arg +opt_block_arg : comma block_arg { $$ = $2; } @@ -2024,6 +2024,10 @@ opt_block_arg : ',' block_arg } ; +comma : ',' + | ',' heredoc_bodies + ; + args : arg { void_expr_error(p, $1); @@ -2036,34 +2040,24 @@ args : arg $$ = cons(new_splat(p, $2), 0); NODE_LINENO($$, $2); } - | args ',' arg + | args comma arg { void_expr_error(p, $3); $$ = push($1, $3); } - | args ',' tSTAR arg + | args comma tSTAR arg { void_expr_error(p, $4); $$ = push($1, new_splat(p, $4)); } - | args ',' heredoc_bodies arg - { - void_expr_error(p, $4); - $$ = push($1, $4); - } - | args ',' heredoc_bodies tSTAR arg - { - void_expr_error(p, $5); - $$ = push($1, new_splat(p, $5)); - } ; -mrhs : args ',' arg +mrhs : args comma arg { void_expr_error(p, $3); $$ = push($1, $3); } - | args ',' tSTAR arg + | args comma tSTAR arg { void_expr_error(p, $4); $$ = push($1, new_splat(p, $4)); @@ -2787,10 +2781,6 @@ regexp : tREGEXP_BEG tREGEXP heredoc : tHEREDOC_BEG ; -opt_heredoc_bodies : /* none */ - | heredoc_bodies - ; - heredoc_bodies : heredoc_body | heredoc_bodies heredoc_body ; @@ -3312,11 +3302,12 @@ rbracket : opt_nl ']' trailer : /* none */ | nl - | ',' + | comma ; term : ';' {yyerrok;} | nl + | heredoc_body ; nl : '\n' @@ -3324,10 +3315,10 @@ nl : '\n' p->lineno++; p->column = 0; } - opt_heredoc_bodies + ; terms : term - | terms ';' {yyerrok;} + | terms term ; none : /* none */ |
