From 0dc15c8459a06f8c75e9b265b1c2513216086ed6 Mon Sep 17 00:00:00 2001 From: Misaki Shioi Date: Sun, 23 Apr 2023 18:10:43 +0900 Subject: [PATCH] Add ++ by Integer#succ --- parse.y | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/parse.y b/parse.y index bd3251e4e1..27d1a43b00 100644 --- a/parse.y +++ b/parse.y @@ -587,6 +587,7 @@ parser_token2id(enum yytokentype tok) TOKEN2ID(tCOLON2); TOKEN2ID(tCOLON3); TOKEN2ID(tOP_ASGN); + TOKEN2ID(tINCOP); TOKEN2ID(tASSOC); TOKEN2ID(tLPAREN); TOKEN2ID(tLPAREN_ARG); @@ -1519,6 +1520,7 @@ static int looking_at_eol_p(struct parser_params *p); %token tANDDOT RUBY_TOKEN(ANDDOT) "&." %token tCOLON2 RUBY_TOKEN(COLON2) "::" %token tCOLON3 ":: at EXPR_BEG" +%token tINCOP "increment-operator" /* ++ */ %token tOP_ASGN "operator-assignment" /* +=, -= etc. */ %token tASSOC "=>" %token tLPAREN "(" @@ -1557,7 +1559,7 @@ static int looking_at_eol_p(struct parser_params *p); %left keyword_or keyword_and %right keyword_not %nonassoc keyword_defined -%right '=' tOP_ASGN +%right '=' tOP_ASGN tINCOP %left modifier_rescue %right '?' ':' %nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3 @@ -4291,6 +4293,15 @@ method_call : fcall paren_args /*% %*/ /*% ripper: aref!($1, escape_Qundef($3)) %*/ } + | primary_value lex_ctxt tINCOP + { + /*%%%*/ + SET_LEX_STATE(EXPR_END); + ID succ = rb_intern("succ"); + $$ = new_qcall(p, $3, $1, succ, Qnull, &@3, &@$); + nd_set_line($$, @3.end_pos.lineno); + /*% %*/ + } ; brace_block : '{' brace_body '}' @@ -10178,6 +10189,9 @@ parser_yylex(struct parser_params *p) } return tUPLUS; } + if (c == '+') { + return tINCOP; + } SET_LEX_STATE(EXPR_BEG); pushback(p, c); return warn_balanced('+', "+", "unary operator");