1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix CMDARG manipulation

* parse.y: Fix CMDARG manipulation. Use CMDARG_P to identify
  keyword_do/keyword_do_block.  [Feature #14506] [Fix GH-1823]

From: Ilya Bylich <ibylich@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-02-22 12:51:41 +00:00
parent 95208d59ca
commit 1727c83584
2 changed files with 23 additions and 37 deletions

40
parse.y
View file

@ -2159,14 +2159,12 @@ command_args : {
lookahead = 1;
}
if (lookahead) CMDARG_POP();
$<val>$ = p->cmdarg_stack;
CMDARG_PUSH(1);
if (lookahead) CMDARG_PUSH(0);
}
call_args
{
/* CMDARG_POP() */
CMDARG_SET($<val>1);
CMDARG_POP();
$$ = $2;
}
;
@ -2287,18 +2285,12 @@ primary : literal
/*% %*/
/*% ripper: paren!(0) %*/
}
| tLPAREN_ARG
| tLPAREN_ARG stmt {SET_LEX_STATE(EXPR_ENDARG);} rparen
{
$<val>1 = p->cmdarg_stack;
CMDARG_SET(0);
}
stmt {SET_LEX_STATE(EXPR_ENDARG);} rparen
{
CMDARG_SET($<val>1);
/*%%%*/
$$ = $3;
$$ = $2;
/*% %*/
/*% ripper: paren!($3) %*/
/*% ripper: paren!($2) %*/
}
| tLPAREN compstmt ')'
{
@ -3034,13 +3026,11 @@ lambda : {
}
f_larglist
{
$<val>$ = p->cmdarg_stack;
CMDARG_SET(0);
CMDARG_PUSH(0);
}
lambda_body
{
p->lex.lpar_beg = $<num>2;
CMDARG_SET($<val>4);
CMDARG_POP();
/*%%%*/
$$ = NEW_LAMBDA($3, $5, &@$);
@ -3217,14 +3207,12 @@ brace_block : '{' brace_body '}'
;
brace_body : {$<vars>$ = dyna_push(p);}
{$<val>$ = p->cmdarg_stack >> 1; CMDARG_SET(0);}
opt_block_param compstmt
{
/*%%%*/
$$ = NEW_ITER($3, $4, &@$);
$$ = NEW_ITER($2, $3, &@$);
/*% %*/
/*% ripper: brace_block!(escape_Qundef($3), $4) %*/
CMDARG_SET($<val>2);
/*% ripper: brace_block!(escape_Qundef($2), $3) %*/
dyna_pop(p, $<vars>1);
}
;
@ -3649,7 +3637,7 @@ string_dvar : tGVAR
symbol : tSYMBEG sym
{
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
SET_LEX_STATE(EXPR_END);
/*%%%*/
$$ = $2;
/*% %*/
@ -3665,7 +3653,7 @@ sym : fname
dsym : tSYMBEG xstring_contents tSTRING_END
{
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
SET_LEX_STATE(EXPR_END);
/*%%%*/
$$ = dsym_node(p, $2, &@$);
/*% %*/
@ -5792,7 +5780,7 @@ parser_string_term(struct parser_params *p, int func)
if (func & STR_FUNC_REGEXP) {
set_yylval_num(regx_options(p));
dispatch_scan_event(p, tREGEXP_END);
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
SET_LEX_STATE(EXPR_END);
return tREGEXP_END;
}
if ((func & STR_FUNC_LABEL) && IS_LABEL_SUFFIX(0)) {
@ -5800,7 +5788,7 @@ parser_string_term(struct parser_params *p, int func)
SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
return tLABEL_END;
}
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
SET_LEX_STATE(EXPR_END);
return tSTRING_END;
}
@ -5816,7 +5804,7 @@ parse_string(struct parser_params *p, rb_strterm_literal_t *quote)
if (func & STR_FUNC_TERM) {
if (func & STR_FUNC_QWORDS) nextc(p); /* delayed term */
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
SET_LEX_STATE(EXPR_END);
p->lex.strterm = 0;
return func & STR_FUNC_REGEXP ? tREGEXP_END : tSTRING_END;
}
@ -6163,7 +6151,7 @@ set_number_literal(struct parser_params *p, VALUE v,
}
set_yylval_literal(v);
add_mark_object(p, v);
SET_LEX_STATE(EXPR_END|EXPR_ENDARG);
SET_LEX_STATE(EXPR_END);
return type;
}
@ -7434,8 +7422,6 @@ parse_ident(struct parser_params *p, int c, int cmd_state)
if (COND_P()) return keyword_do_cond;
if (CMDARG_P() && !IS_lex_state_for(state, EXPR_CMDARG))
return keyword_do_block;
if (IS_lex_state_for(state, (EXPR_BEG | EXPR_ENDARG)))
return keyword_do_block;
return keyword_do;
}
if (IS_lex_state_for(state, (EXPR_BEG | EXPR_LABELED)))

View file

@ -60,11 +60,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
[[1, 7], :on_rparen, ")", Ripper::EXPR_ENDFN],
[[1, 8], :on_kw, "end", Ripper::EXPR_END]],
Ripper.lex("def m(a)end")
assert_equal [[[1, 0], :on_int, "1", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
assert_equal [[[1, 0], :on_int, "1", Ripper::EXPR_END],
[[1, 1], :on_nl, "\n", Ripper::EXPR_BEG],
[[2, 0], :on_int, "2", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
[[2, 0], :on_int, "2", Ripper::EXPR_END],
[[2, 1], :on_nl, "\n", Ripper::EXPR_BEG],
[[3, 0], :on_int, "3", Ripper::EXPR_END | Ripper::EXPR_ENDARG]],
[[3, 0], :on_int, "3", Ripper::EXPR_END]],
Ripper.lex("1\n2\n3")
assert_equal [[[1, 0], :on_heredoc_beg, "<<""EOS", Ripper::EXPR_BEG],
[[1, 5], :on_nl, "\n", Ripper::EXPR_BEG],
@ -86,21 +86,21 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
Ripper.lex("/foo\n\u3020/")
assert_equal [[[1, 0], :on_tstring_beg, "'", Ripper::EXPR_BEG],
[[1, 1], :on_tstring_content, "foo\n\xe3\x80\xa0", Ripper::EXPR_BEG],
[[2, 3], :on_tstring_end, "'", Ripper::EXPR_END | Ripper::EXPR_ENDARG]],
[[2, 3], :on_tstring_end, "'", Ripper::EXPR_END]],
Ripper.lex("'foo\n\xe3\x80\xa0'")
assert_equal [[[1, 0], :on_tstring_beg, "'", Ripper::EXPR_BEG],
[[1, 1], :on_tstring_content, "\u3042\n\u3044", Ripper::EXPR_BEG],
[[2, 3], :on_tstring_end, "'", Ripper::EXPR_END | Ripper::EXPR_ENDARG]],
[[2, 3], :on_tstring_end, "'", Ripper::EXPR_END]],
Ripper.lex("'\u3042\n\u3044'")
assert_equal [[[1, 0], :on_rational, "1r", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
assert_equal [[[1, 0], :on_rational, "1r", Ripper::EXPR_END],
[[1, 2], :on_nl, "\n", Ripper::EXPR_BEG],
[[2, 0], :on_imaginary, "2i", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
[[2, 0], :on_imaginary, "2i", Ripper::EXPR_END],
[[2, 2], :on_nl, "\n", Ripper::EXPR_BEG],
[[3, 0], :on_imaginary, "3ri", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
[[3, 0], :on_imaginary, "3ri", Ripper::EXPR_END],
[[3, 3], :on_nl, "\n", Ripper::EXPR_BEG],
[[4, 0], :on_rational, "4.2r", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
[[4, 0], :on_rational, "4.2r", Ripper::EXPR_END],
[[4, 4], :on_nl, "\n", Ripper::EXPR_BEG],
[[5, 0], :on_imaginary, "5.6ri", Ripper::EXPR_END | Ripper::EXPR_ENDARG],
[[5, 0], :on_imaginary, "5.6ri", Ripper::EXPR_END],
],
Ripper.lex("1r\n2i\n3ri\n4.2r\n5.6ri")
assert_equal [[[1, 0], :on_heredoc_beg, "<<~EOS", Ripper::EXPR_BEG],