ruby-changes:49652
From: mame <ko1@a...>
Date: Thu, 11 Jan 2018 22:42:21 +0900 (JST)
Subject: [ruby-changes:49652] mame:r61768 (trunk): parse.y: simplify and add a comment for paren_nest and lpar_beg
mame 2018-01-11 22:42:15 +0900 (Thu, 11 Jan 2018) New Revision: 61768 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61768 Log: parse.y: simplify and add a comment for paren_nest and lpar_beg Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 61767) +++ parse.y (revision 61768) @@ -201,8 +201,11 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L201 const char *ptok; long gets_ptr; enum lex_state_e state; + /* track the nest level of any parens "()[]{}" */ int paren_nest; + /* keep paren_nest at the beginning of lambda "->" to detect tLAMBEG and keyowrd_do_LAMBDA */ int lpar_beg; + /* track the nest level of only braces "{}" */ int brace_nest; } lex; stack_type cond_stack; @@ -343,7 +346,7 @@ static int parser_yyerror(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L346 #define NODE_CALL_Q(q) (CALL_Q_P(q) ? NODE_QCALL : NODE_CALL) #define NEW_QCALL(q,r,m,a,loc) NEW_NODE(NODE_CALL_Q(q),r,m,a,loc) -#define lambda_beginning_p() (lpar_beg && lpar_beg == paren_nest) +#define lambda_beginning_p() (lpar_beg == paren_nest) static enum yytokentype yylex(YYSTYPE*, YYLTYPE*, struct parser_params*); @@ -3415,7 +3418,7 @@ lambda : { https://github.com/ruby/ruby/blob/trunk/parse.y#L3418 } { $<num>$ = lpar_beg; - lpar_beg = ++paren_nest; + lpar_beg = paren_nest; } f_larglist { @@ -7991,8 +7994,7 @@ parse_ident(struct parser_params *parser https://github.com/ruby/ruby/blob/trunk/parse.y#L7994 } if (kw->id[0] == keyword_do) { if (lambda_beginning_p()) { - lpar_beg = 0; - --paren_nest; + lpar_beg = -1; /* make lambda_beginning_p() == FALSE in the body of "-> do ... end" */ return keyword_do_LAMBDA; } if (COND_P()) return keyword_do_cond; @@ -8487,7 +8489,6 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8489 case ')': case ']': - paren_nest--; case '}': COND_LEXPOP(); CMDARG_LEXPOP(); @@ -8498,6 +8499,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8499 if (c == '}') { if (!brace_nest--) c = tSTRING_DEND; } + if (c != tSTRING_DEND) paren_nest--; return c; case ':': @@ -8630,12 +8632,12 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8632 ++brace_nest; if (lambda_beginning_p()) { SET_LEX_STATE(EXPR_BEG); - lpar_beg = 0; - --paren_nest; COND_PUSH(0); CMDARG_PUSH(0); + paren_nest++; return tLAMBEG; } + paren_nest++; if (IS_lex_state(EXPR_LABELED)) c = tLBRACE; /* hash */ else if (IS_lex_state(EXPR_ARG_ANY | EXPR_END | EXPR_ENDFN)) @@ -11098,6 +11100,7 @@ parser_initialize(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L11100 /* note: we rely on TypedData_Make_Struct to set most fields to 0 */ command_start = TRUE; ruby_sourcefile_string = Qnil; + lpar_beg = -1; /* make lambda_beginning_p() == FALSE at first */ #ifdef RIPPER parser->delayed = Qnil; parser->result = Qnil; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/