зеркало из https://github.com/github/ruby.git
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.
This commit is contained in:
Родитель
9ee99fbd8a
Коммит
8d1b188864
16
parse.y
16
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;
|
||||
$<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;
|
||||
}
|
||||
;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче