From 043f010c28e82ea38978bf8ed885416f133b5b75 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 13 Jun 2019 22:03:10 +0900 Subject: [PATCH] parse.y: moved pipeline to expr To allow arguments without parentheses. --- parse.y | 48 ++++++++++++++++++++++++++-------------- test/ruby/test_syntax.rb | 2 +- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/parse.y b/parse.y index 6f282d8014..a31139fbef 100644 --- a/parse.y +++ b/parse.y @@ -1496,6 +1496,37 @@ expr : command_call $$ = call_uni_op(p, method_cond(p, $2, &@2), '!', &@1, &@$); } | arg + | pipeline + ; + +pipeline : expr tPIPE operation2 opt_paren_args + { + /*%%%*/ + $$ = new_command_qcall(p, ID2VAL(idPIPE), $1, $3, $4, Qnull, &@3, &@$); + /*% %*/ + /*% ripper: command_call!($1, ID2VAL(idPIPE), $3, $4) %*/ + } + | expr tPIPE operation2 opt_paren_args brace_block + { + /*%%%*/ + $$ = new_command_qcall(p, ID2VAL(idPIPE), $1, $3, $4, $5, &@3, &@$); + /*% %*/ + /*% ripper: method_add_block!(command_call!($1, ID2VAL(idPIPE), $3, $4), $5) %*/ + } + | expr tPIPE operation2 command_args + { + /*%%%*/ + $$ = new_command_qcall(p, ID2VAL(idPIPE), $1, $3, $4, Qnull, &@3, &@$); + /*% %*/ + /*% ripper: command_call!($1, ID2VAL(idPIPE), $3, $4) %*/ + } + | expr tPIPE operation2 command_args do_block + { + /*%%%*/ + $$ = new_command_qcall(p, ID2VAL(idPIPE), $1, $3, $4, $5, &@3, &@$); + /*% %*/ + /*% ripper: method_add_block!(command_call!($1, ID2VAL(idPIPE), $3, $4), $5) %*/ + } ; expr_value : expr @@ -2271,29 +2302,12 @@ arg : lhs '=' arg_rhs /*% %*/ /*% ripper: ifop!($1, $3, $6) %*/ } - | pipeline | primary { $$ = $1; } ; -pipeline : arg tPIPE operation2 opt_paren_args - { - /*%%%*/ - $$ = new_command_qcall(p, ID2VAL(idPIPE), $1, $3, $4, Qnull, &@3, &@$); - /*% %*/ - /*% ripper: command_call!($1, ID2VAL(idPIPE), $3, $4) %*/ - } - | arg tPIPE operation2 opt_paren_args brace_block - { - /*%%%*/ - $$ = new_command_qcall(p, ID2VAL(idPIPE), $1, $3, $4, $5, &@3, &@$); - /*% %*/ - /*% ripper: method_add_block!(command_call!($1, ID2VAL(idPIPE), $3, $4), $5) %*/ - } - ; - relop : '>' {$$ = '>';} | '<' {$$ = '<';} | tGEQ {$$ = idGE;} diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 7bffb8790b..b3e2183830 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1382,7 +1382,7 @@ eom def test_pipeline_operator assert_valid_syntax('x |> y') x = nil - assert_equal("121", eval('x = 12 |> pow(2) |> to_s(11)')) + assert_equal("121", eval('x = 12 |> pow(2) |> to_s 11')) assert_equal(12, x) end