diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c index 05687497ac..b2e8650c48 100644 --- a/ext/ripper/eventids2.c +++ b/ext/ripper/eventids2.c @@ -237,6 +237,7 @@ ripper_token2eventid(enum yytokentype tok) [tNMATCH] = O(op), [tNTH_REF] = O(backref), [tOP_ASGN] = O(op), + [tINCOP] = O(op), [tOROP] = O(op), [tPOW] = O(op), [tQWORDS_BEG] = O(qwords_beg), diff --git a/parse.y b/parse.y index bd3251e4e1..096a06f03b 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); @@ -1520,6 +1521,7 @@ static int looking_at_eol_p(struct parser_params *p); %token tCOLON2 RUBY_TOKEN(COLON2) "::" %token tCOLON3 ":: at EXPR_BEG" %token tOP_ASGN "operator-assignment" /* +=, -= etc. */ +%token tINCOP "increment-operator" /* ++ */ %token tASSOC "=>" %token tLPAREN "(" %token tLPAREN_ARG "( arg" @@ -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 @@ -2640,6 +2642,30 @@ arg : lhs '=' lex_ctxt arg_rhs /*% %*/ /*% ripper: opassign!($1, $2, $4) %*/ } + | var_lhs lex_ctxt tINCOP + { + /*%%%*/ + SET_LEX_STATE(EXPR_END); + + VALUE v = rb_cstr_to_inum("1", 16, FALSE); + NODE *x = NEW_LIT(v, &NULL_LOC); + YYLTYPE _cur_loc; + rb_parser_set_location(p, &_cur_loc); + RB_OBJ_WRITTEN(p->ast, Qnil, x); + + $$ = new_op_assign(p, $1, '+', x, $2, &@$); + /*% + VALUE v = rb_cstr_to_inum("1", 16, FALSE); + add_mark_object(p, (v)); + VALUE v1, v2, v3, v4; + v1 = (yyvsp[-2].val); + v2 = (yyvsp[0].val); + v3 = v; + v4 = dispatch3(p, v1, v2, v3); + (yyval.val) = v4; + SET_LEX_STATE(EXPR_END); + %*/ + } | primary_value '[' opt_call_args rbracket tOP_ASGN lex_ctxt arg_rhs { /*%%%*/ @@ -10178,6 +10204,10 @@ parser_yylex(struct parser_params *p) } return tUPLUS; } + if (c == '+') { + SET_LEX_STATE(EXPR_BEG); + return tINCOP; + } SET_LEX_STATE(EXPR_BEG); pushback(p, c); return warn_balanced('+', "+", "unary operator");