diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-09 12:33:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-09 12:33:38 +0000 |
commit | 9c2c2f77ba4b346e99f00862ac6340ff1a33a82c (patch) | |
tree | 9f076f1972b344b5e3e6594c3cbaf397ae81699e | |
parent | d68a3d3bc11c06edbfca6e02839acc1f6cbe0685 (diff) | |
download | ruby-9c2c2f77ba4b346e99f00862ac6340ff1a33a82c.tar.gz |
parse.y: insane syntax
* parse.y (primary): save/restore COND and CMDARG stacks at method
definition, to distinguish do_block and do_cond properly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | parse.y | 34 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 5 |
2 files changed, 31 insertions, 8 deletions
@@ -2900,22 +2900,31 @@ primary : literal $<num>$ = in_def; in_def = 1; } + { + $<val>1 = cond_stack; + $<val>$ = cmdarg_stack; + COND_SET(0); + CMDARG_SET(0); + } f_arglist bodystmt k_end { /*%%%*/ - NODE *body = remove_begin($6); + NODE *body = remove_begin($7); reduce_nodes(&body); - $$ = NEW_DEFN($2, $5, body, &@$); - nd_set_line($$->nd_defn, @7.end_pos.lineno); + $$ = NEW_DEFN($2, $6, body, &@$); + nd_set_line($$->nd_defn, @8.end_pos.lineno); set_line_body(body, @1.beg_pos.lineno); /*% - $$ = dispatch3(def, $2, $5, $6); + $$ = dispatch3(def, $2, $6, $7); %*/ local_pop(); in_def = $<num>4 & 1; current_arg = $<id>3; + + COND_SET($<val>1); + CMDARG_SET($<val>5); } | k_def singleton dot_or_colon {SET_LEX_STATE(EXPR_FNAME);} fname { @@ -2926,22 +2935,31 @@ primary : literal $<id>$ = current_arg; current_arg = 0; } + { + $<val>1 = cond_stack; + $<val>$ = cmdarg_stack; + COND_SET(0); + CMDARG_SET(0); + } f_arglist bodystmt k_end { /*%%%*/ - NODE *body = remove_begin($8); + NODE *body = remove_begin($9); reduce_nodes(&body); - $$ = NEW_DEFS($2, $5, $7, body, &@$); - nd_set_line($$->nd_defn, @9.end_pos.lineno); + $$ = NEW_DEFS($2, $5, $8, body, &@$); + nd_set_line($$->nd_defn, @10.end_pos.lineno); set_line_body(body, @1.beg_pos.lineno); /*% - $$ = dispatch5(defs, $2, $<val>3, $5, $7, $8); + $$ = dispatch5(defs, $2, $<val>3, $5, $8, $9); %*/ local_pop(); in_def = $<num>4 & 1; current_arg = $<id>6; + + COND_SET($<val>1); + CMDARG_SET($<val>7); } | keyword_break { diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 57ce169cd3..bf9f4998ac 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1181,6 +1181,11 @@ eom assert_equal(line, e.backtrace_locations[0].lineno) end + def test_methoddef_in_cond + assert_valid_syntax('while def foo; tap do end; end; break; end') + assert_valid_syntax('while def foo a = tap do end; end; break; end') + end + private def not_label(x) @result = x; @not_label ||= nil end |