Skip to content

Commit

Permalink
Relax 'void value expression' check that was too strict
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Nov 24, 2016
1 parent 1c95939 commit 227daa8
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions mrbgems/mruby-compiler/core/parse.y
Expand Up @@ -1098,7 +1098,7 @@ heredoc_end(parser_state *p)
%type <nd> literal numeric cpath symbol %type <nd> literal numeric cpath symbol
%type <nd> top_compstmt top_stmts top_stmt %type <nd> top_compstmt top_stmts top_stmt
%type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call %type <nd> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
%type <nd> expr_value arg0 arg_rhs primary_value %type <nd> expr_value arg_rhs primary_value
%type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure %type <nd> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
%type <nd> args call_args opt_call_args %type <nd> args call_args opt_call_args
%type <nd> paren_args opt_paren_args variable %type <nd> paren_args opt_paren_args variable
Expand Down Expand Up @@ -1396,7 +1396,7 @@ expr : command_call
{ {
$$ = call_uni_op(p, cond($2), "!"); $$ = call_uni_op(p, cond($2), "!");
} }
| arg0 | arg
; ;


expr_value : expr expr_value : expr
Expand Down Expand Up @@ -1738,7 +1738,7 @@ reswords : keyword__LINE__ | keyword__FILE__ | keyword__ENCODING__
| keyword_while | keyword_until | keyword_while | keyword_until
; ;


arg0 : lhs '=' arg_rhs arg : lhs '=' arg_rhs
{ {
$$ = new_asgn(p, $1, $3); $$ = new_asgn(p, $1, $3);
} }
Expand Down Expand Up @@ -1911,16 +1911,6 @@ arg0 : lhs '=' arg_rhs
} }
; ;


arg : arg0
{
if (!$1) $$ = new_nil(p);
else {
void_expr_error(p, $1);
$$ = $1;
}
}
;

aref_args : none aref_args : none
| args trailer | args trailer
{ {
Expand All @@ -1939,8 +1929,14 @@ aref_args : none
; ;


arg_rhs : arg %prec tOP_ASGN arg_rhs : arg %prec tOP_ASGN
{
void_expr_error(p, $1);
$$ = $1;
}
| arg modifier_rescue arg | arg modifier_rescue arg
{ {
void_expr_error(p, $1);
void_expr_error(p, $3);
$$ = new_mod_rescue(p, $1, $3); $$ = new_mod_rescue(p, $1, $3);
} }
; ;
Expand Down Expand Up @@ -2030,42 +2026,51 @@ opt_block_arg : ',' block_arg


args : arg args : arg
{ {
void_expr_error(p, $1);
$$ = cons($1, 0); $$ = cons($1, 0);
NODE_LINENO($$, $1); NODE_LINENO($$, $1);
} }
| tSTAR arg | tSTAR arg
{ {
void_expr_error(p, $2);
$$ = cons(new_splat(p, $2), 0); $$ = cons(new_splat(p, $2), 0);
NODE_LINENO($$, $2); NODE_LINENO($$, $2);
} }
| args ',' arg | args ',' arg
{ {
void_expr_error(p, $3);
$$ = push($1, $3); $$ = push($1, $3);
} }
| args ',' tSTAR arg | args ',' tSTAR arg
{ {
void_expr_error(p, $4);
$$ = push($1, new_splat(p, $4)); $$ = push($1, new_splat(p, $4));
} }
| args ',' heredoc_bodies arg | args ',' heredoc_bodies arg
{ {
void_expr_error(p, $4);
$$ = push($1, $4); $$ = push($1, $4);
} }
| args ',' heredoc_bodies tSTAR arg | args ',' heredoc_bodies tSTAR arg
{ {
void_expr_error(p, $5);
$$ = push($1, new_splat(p, $5)); $$ = push($1, new_splat(p, $5));
} }
; ;


mrhs : args ',' arg mrhs : args ',' arg
{ {
void_expr_error(p, $3);
$$ = push($1, $3); $$ = push($1, $3);
} }
| args ',' tSTAR arg | args ',' tSTAR arg
{ {
void_expr_error(p, $4);
$$ = push($1, new_splat(p, $4)); $$ = push($1, new_splat(p, $4));
} }
| tSTAR arg | tSTAR arg
{ {
void_expr_error(p, $2);
$$ = list1(new_splat(p, $2)); $$ = list1(new_splat(p, $2));
} }
; ;
Expand Down

0 comments on commit 227daa8

Please sign in to comment.