From f169043d81524b5b529f2c1e9c35437ba5bc3a7a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 23 Apr 2019 13:14:27 +0900 Subject: Add pipeline operator [Feature #15799] --- parse.y | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index c78f5139f7..6f282d8014 100644 --- a/parse.y +++ b/parse.y @@ -1002,7 +1002,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in %type literal numeric simple_numeric ssym dsym symbol cpath %type top_compstmt top_stmts top_stmt begin_block %type bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call -%type expr_value expr_value_do arg_value primary_value fcall rel_expr +%type expr_value expr_value_do arg_value primary_value fcall rel_expr pipeline %type if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure %type args call_args opt_call_args %type paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail @@ -1060,6 +1060,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in %token tANDDOT RUBY_TOKEN(ANDDOT) "&." %token tCOLON2 RUBY_TOKEN(COLON2) "::" %token tMETHREF RUBY_TOKEN(METHREF) ".:" +%token tPIPE RUBY_TOKEN(PIPE) "|>" %token tCOLON3 ":: at EXPR_BEG" %token tOP_ASGN "operator-assignment" /* +=, -= etc. */ %token tASSOC "=>" @@ -1095,6 +1096,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in %nonassoc modifier_if modifier_unless modifier_while modifier_until %left keyword_or keyword_and %right keyword_not +%left tPIPE %nonassoc keyword_defined %right '=' tOP_ASGN %left modifier_rescue @@ -2269,12 +2271,29 @@ 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;} @@ -8924,6 +8943,10 @@ parser_yylex(struct parser_params *p) SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } + if (c == '>') { + SET_LEX_STATE(EXPR_DOT); + return tPIPE; + } SET_LEX_STATE(IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG|EXPR_LABEL); pushback(p, c); return '|'; -- cgit v1.2.3