Reorganize heredoc rules; fix #3273

The following codes used to be SyntaxError:

(1)
  a = <<-EOD;
  hello
  EOD

(2)
  <<-EOD.bla begin
  k
  EOD
  end
parent ac561a52
...@@ -1918,7 +1918,7 @@ aref_args : none ...@@ -1918,7 +1918,7 @@ aref_args : none
$$ = $1; $$ = $1;
NODE_LINENO($$, $1); NODE_LINENO($$, $1);
} }
| args ',' assocs trailer | args comma assocs trailer
{ {
$$ = push($1, new_hash(p, $3)); $$ = push($1, new_hash(p, $3));
} }
...@@ -1958,7 +1958,7 @@ opt_call_args : none ...@@ -1958,7 +1958,7 @@ opt_call_args : none
$$ = cons($1,0); $$ = cons($1,0);
NODE_LINENO($$, $1); NODE_LINENO($$, $1);
} }
| args ',' assocs ',' | args comma assocs ','
{ {
$$ = cons(push($1, new_hash(p, $3)), 0); $$ = cons(push($1, new_hash(p, $3)), 0);
NODE_LINENO($$, $1); NODE_LINENO($$, $1);
...@@ -1985,7 +1985,7 @@ call_args : command ...@@ -1985,7 +1985,7 @@ call_args : command
$$ = cons(list1(new_hash(p, $1)), $2); $$ = cons(list1(new_hash(p, $1)), $2);
NODE_LINENO($$, $1); NODE_LINENO($$, $1);
} }
| args ',' assocs opt_block_arg | args comma assocs opt_block_arg
{ {
$$ = cons(push($1, new_hash(p, $3)), $4); $$ = cons(push($1, new_hash(p, $3)), $4);
NODE_LINENO($$, $1); NODE_LINENO($$, $1);
...@@ -2014,7 +2014,7 @@ block_arg : tAMPER arg ...@@ -2014,7 +2014,7 @@ block_arg : tAMPER arg
} }
; ;
opt_block_arg : ',' block_arg opt_block_arg : comma block_arg
{ {
$$ = $2; $$ = $2;
} }
...@@ -2024,6 +2024,10 @@ opt_block_arg : ',' block_arg ...@@ -2024,6 +2024,10 @@ opt_block_arg : ',' block_arg
} }
; ;
comma : ','
| ',' heredoc_bodies
;
args : arg args : arg
{ {
void_expr_error(p, $1); void_expr_error(p, $1);
...@@ -2036,34 +2040,24 @@ args : arg ...@@ -2036,34 +2040,24 @@ args : arg
$$ = cons(new_splat(p, $2), 0); $$ = cons(new_splat(p, $2), 0);
NODE_LINENO($$, $2); NODE_LINENO($$, $2);
} }
| args ',' arg | args comma arg
{ {
void_expr_error(p, $3); void_expr_error(p, $3);
$$ = push($1, $3); $$ = push($1, $3);
} }
| args ',' tSTAR arg | args comma tSTAR arg
{ {
void_expr_error(p, $4); void_expr_error(p, $4);
$$ = push($1, new_splat(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); void_expr_error(p, $3);
$$ = push($1, $3); $$ = push($1, $3);
} }
| args ',' tSTAR arg | args comma tSTAR arg
{ {
void_expr_error(p, $4); void_expr_error(p, $4);
$$ = push($1, new_splat(p, $4)); $$ = push($1, new_splat(p, $4));
...@@ -2787,10 +2781,6 @@ regexp : tREGEXP_BEG tREGEXP ...@@ -2787,10 +2781,6 @@ regexp : tREGEXP_BEG tREGEXP
heredoc : tHEREDOC_BEG heredoc : tHEREDOC_BEG
; ;
opt_heredoc_bodies : /* none */
| heredoc_bodies
;
heredoc_bodies : heredoc_body heredoc_bodies : heredoc_body
| heredoc_bodies heredoc_body | heredoc_bodies heredoc_body
; ;
...@@ -3312,11 +3302,12 @@ rbracket : opt_nl ']' ...@@ -3312,11 +3302,12 @@ rbracket : opt_nl ']'
trailer : /* none */ trailer : /* none */
| nl | nl
| ',' | comma
; ;
term : ';' {yyerrok;} term : ';' {yyerrok;}
| nl | nl
| heredoc_body
; ;
nl : '\n' nl : '\n'
...@@ -3324,10 +3315,10 @@ nl : '\n' ...@@ -3324,10 +3315,10 @@ nl : '\n'
p->lineno++; p->lineno++;
p->column = 0; p->column = 0;
} }
opt_heredoc_bodies ;
terms : term terms : term
| terms ';' {yyerrok;} | terms term
; ;
none : /* none */ none : /* none */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment