From 8d1b18886459d3f92cbaf6547f22f893a9a2ced1 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 9 Oct 2020 00:19:25 +0900 Subject: 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. --- parse.y | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index f8441e867f..1a6887e983 100644 --- a/parse.y +++ b/parse.y @@ -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; - $$ = NEW_NODE(NODE_SELF, /*vid*/cur_arg, /*mid*/fname, /*state*/in_def, &@$); + $$ = 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"); } - $1 = p->ctxt; p->ctxt.in_class = 1; local_push(p, 0); } @@ -3087,7 +3087,6 @@ primary : literal } | k_class tLSHFT expr { - $$ = 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 = $4.in_def; - p->ctxt.in_class = $4.in_class; + p->ctxt.in_def = $1.in_def; + p->ctxt.in_class = $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"); } - $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", &@$); + $$ = p->ctxt; } ; k_module : keyword_module { token_info_push(p, "module", &@$); + $$ = p->ctxt; } ; -- cgit v1.2.3