diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-10-09 00:19:25 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-10-09 13:44:48 +0900 |
commit | 8d1b18886459d3f92cbaf6547f22f893a9a2ced1 (patch) | |
tree | c7cbba22865ff192d433e1d2e9e9b37aae5fa8f1 /parse.y | |
parent | 9ee99fbd8a3ea38d6286e4ecdfab146ee4a00eb5 (diff) |
Refactored lex_context management
Save and restore `lex_context` as-is wholely, and save in
`k_class` and `k_module` to workaround look-ahead reading.
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -956,8 +956,9 @@ rescued_expr(struct parser_params *p, NODE *arg, NODE *rescue, static void restore_defun(struct parser_params *p, NODE *name) { + YYSTYPE c = {.val = name->nd_cval}; p->cur_arg = name->nd_vid; - p->ctxt.in_def = name->nd_state & 1; + p->ctxt.in_def = c.ctxt.in_def; } #ifndef RIPPER @@ -1689,12 +1690,12 @@ def_name : fname { ID fname = get_id($1); ID cur_arg = p->cur_arg; - int in_def = p->ctxt.in_def; + YYSTYPE c = {.ctxt = p->ctxt}; numparam_name(p, fname); local_push(p, 0); p->cur_arg = 0; p->ctxt.in_def = 1; - $<node>$ = NEW_NODE(NODE_SELF, /*vid*/cur_arg, /*mid*/fname, /*state*/in_def, &@$); + $<node>$ = NEW_NODE(NODE_SELF, /*vid*/cur_arg, /*mid*/fname, /*cval*/c.val, &@$); /*%%%*/ /*% $$ = NEW_RIPPER(fname, get_value($1), $$, &NULL_LOC); @@ -3068,7 +3069,6 @@ primary : literal YYLTYPE loc = code_loc_gen(&@1, &@2); yyerror1(&loc, "class definition in method body"); } - $<ctxt>1 = p->ctxt; p->ctxt.in_class = 1; local_push(p, 0); } @@ -3087,7 +3087,6 @@ primary : literal } | k_class tLSHFT expr { - $<ctxt>$ = p->ctxt; p->ctxt.in_def = 0; p->ctxt.in_class = 0; local_push(p, 0); @@ -3104,8 +3103,8 @@ primary : literal /*% %*/ /*% ripper: sclass!($3, $6) %*/ local_pop(p); - p->ctxt.in_def = $<ctxt>4.in_def; - p->ctxt.in_class = $<ctxt>4.in_class; + p->ctxt.in_def = $<ctxt>1.in_def; + p->ctxt.in_class = $<ctxt>1.in_class; } | k_module cpath { @@ -3113,7 +3112,6 @@ primary : literal YYLTYPE loc = code_loc_gen(&@1, &@2); yyerror1(&loc, "module definition in method body"); } - $<ctxt>1 = p->ctxt; p->ctxt.in_class = 1; local_push(p, 0); } @@ -3249,12 +3247,14 @@ k_for : keyword_for k_class : keyword_class { token_info_push(p, "class", &@$); + $<ctxt>$ = p->ctxt; } ; k_module : keyword_module { token_info_push(p, "module", &@$); + $<ctxt>$ = p->ctxt; } ; |