Skip to content

Commit

Permalink
Reorganize heredoc rules; fix #3273
Browse files Browse the repository at this point in the history
The following codes used to be SyntaxError:

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

(2)
  <<-EOD.bla begin
  k
  EOD
  end
  • Loading branch information
matz committed Dec 4, 2016
1 parent ac561a5 commit 43512cc
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions mrbgems/mruby-compiler/core/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ aref_args : none
$$ = $1;
NODE_LINENO($$, $1);
}
| args ',' assocs trailer
| args comma assocs trailer
{
$$ = push($1, new_hash(p, $3));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -2014,7 +2014,7 @@ block_arg : tAMPER arg
}
;

opt_block_arg : ',' block_arg
opt_block_arg : comma block_arg
{
$$ = $2;
}
Expand All @@ -2024,6 +2024,10 @@ opt_block_arg : ',' block_arg
}
;

comma : ','
| ',' heredoc_bodies
;

args : arg
{
void_expr_error(p, $1);
Expand All @@ -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));
Expand Down Expand Up @@ -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
;
Expand Down Expand Up @@ -3312,22 +3302,23 @@ rbracket : opt_nl ']'

trailer : /* none */
| nl
| ','
| comma
;

term : ';' {yyerrok;}
| nl
| heredoc_body
;

nl : '\n'
{
p->lineno++;
p->column = 0;
}
opt_heredoc_bodies
;

terms : term
| terms ';' {yyerrok;}
| terms term
;

none : /* none */
Expand Down

0 comments on commit 43512cc

Please sign in to comment.