mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: brace after literal arg
* parse.y (symbol, dsym, parser_set_number_literal, parser_yylex): set state to END too not only ENDARG and after a literal, so that a left brace after it should be a primary block bound to the literal, which causes syntax error. [ruby-core:81037] [Bug #13547] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
046c94380b
commit
99871095e6
2 changed files with 16 additions and 4 deletions
10
parse.y
10
parse.y
|
@ -4049,7 +4049,7 @@ string_dvar : tGVAR
|
||||||
|
|
||||||
symbol : tSYMBEG sym
|
symbol : tSYMBEG sym
|
||||||
{
|
{
|
||||||
SET_LEX_STATE(EXPR_ENDARG);
|
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
/*%
|
/*%
|
||||||
|
@ -4066,7 +4066,7 @@ sym : fname
|
||||||
|
|
||||||
dsym : tSYMBEG xstring_contents tSTRING_END
|
dsym : tSYMBEG xstring_contents tSTRING_END
|
||||||
{
|
{
|
||||||
SET_LEX_STATE(EXPR_ENDARG);
|
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
$$ = dsym_node($2);
|
$$ = dsym_node($2);
|
||||||
/*%
|
/*%
|
||||||
|
@ -6526,7 +6526,7 @@ parser_set_number_literal(struct parser_params *parser, VALUE v, int type, int s
|
||||||
type = tIMAGINARY;
|
type = tIMAGINARY;
|
||||||
}
|
}
|
||||||
set_yylval_literal(v);
|
set_yylval_literal(v);
|
||||||
SET_LEX_STATE(EXPR_ENDARG);
|
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7884,9 +7884,11 @@ parser_yylex(struct parser_params *parser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (token == tSTRING_END || token == tREGEXP_END || token == tLABEL_END) {
|
if (token == tSTRING_END || token == tREGEXP_END || token == tLABEL_END) {
|
||||||
|
const enum lex_state_e next_state =
|
||||||
|
token == tLABEL_END ? EXPR_BEG|EXPR_LABEL : EXPR_END|EXPR_ENDARG;
|
||||||
rb_gc_force_recycle((VALUE)lex_strterm);
|
rb_gc_force_recycle((VALUE)lex_strterm);
|
||||||
lex_strterm = 0;
|
lex_strterm = 0;
|
||||||
SET_LEX_STATE(token == tLABEL_END ? EXPR_BEG|EXPR_LABEL : EXPR_ENDARG);
|
SET_LEX_STATE(next_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
|
|
|
@ -952,6 +952,16 @@ eom
|
||||||
assert_equal(:ok, result)
|
assert_equal(:ok, result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_brace_after_literal_argument
|
||||||
|
bug = '[ruby-core:81037] [Bug #13547]'
|
||||||
|
error = /unexpected '{'/
|
||||||
|
assert_syntax_error('m "x" {}', error)
|
||||||
|
assert_syntax_error('m 1 {}', error, bug)
|
||||||
|
assert_syntax_error('m 1.0 {}', error, bug)
|
||||||
|
assert_syntax_error('m :m {}', error, bug)
|
||||||
|
assert_syntax_error('m :"#{m}" {}', error, bug)
|
||||||
|
end
|
||||||
|
|
||||||
def test_return_toplevel
|
def test_return_toplevel
|
||||||
feature4840 = '[ruby-core:36785] [Feature #4840]'
|
feature4840 = '[ruby-core:36785] [Feature #4840]'
|
||||||
code = "#{<<~"begin;"}\n#{<<~"end;"}"
|
code = "#{<<~"begin;"}\n#{<<~"end;"}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue