refactor parser lineno adjustment; ref #1667

parent dd70ae0b
...@@ -109,7 +109,7 @@ struct mrb_parser_state { ...@@ -109,7 +109,7 @@ struct mrb_parser_state {
#endif #endif
mrbc_context *cxt; mrbc_context *cxt;
char const *filename; char const *filename;
int lineno, beg_lineno; int lineno;
int column; int column;
enum mrb_lex_state_enum lstate; enum mrb_lex_state_enum lstate;
......
...@@ -62,8 +62,7 @@ typedef unsigned int stack_type; ...@@ -62,8 +62,7 @@ typedef unsigned int stack_type;
#define CMDARG_LEXPOP() BITSTACK_LEXPOP(p->cmdarg_stack) #define CMDARG_LEXPOP() BITSTACK_LEXPOP(p->cmdarg_stack)
#define CMDARG_P() BITSTACK_SET_P(p->cmdarg_stack) #define CMDARG_P() BITSTACK_SET_P(p->cmdarg_stack)
#define SET_BEG_LINENO(n) (p->beg_lineno = n) #define SET_LINENO(c,n) ((c)->lineno = (n))
#define CLEAR_BEG_LINENO() (p->beg_lineno = 0)
#define sym(x) ((mrb_sym)(intptr_t)(x)) #define sym(x) ((mrb_sym)(intptr_t)(x))
#define nsym(x) ((node*)(intptr_t)(x)) #define nsym(x) ((node*)(intptr_t)(x))
...@@ -123,7 +122,7 @@ cons_gen(parser_state *p, node *car, node *cdr) ...@@ -123,7 +122,7 @@ cons_gen(parser_state *p, node *car, node *cdr)
c->car = car; c->car = car;
c->cdr = cdr; c->cdr = cdr;
c->lineno = p->beg_lineno ? p->beg_lineno : p->lineno; c->lineno = p->lineno;
c->filename_index = p->current_filename_index; c->filename_index = p->current_filename_index;
return c; return c;
} }
...@@ -2166,9 +2165,8 @@ primary : literal ...@@ -2166,9 +2165,8 @@ primary : literal
bodystmt bodystmt
keyword_end keyword_end
{ {
SET_BEG_LINENO($<num>2);
$$ = new_class(p, $3, $4, $6); $$ = new_class(p, $3, $4, $6);
CLEAR_BEG_LINENO(); SET_LINENO($$, $<num>2);
local_resume(p, $<nd>5); local_resume(p, $<nd>5);
} }
| keyword_class | keyword_class
...@@ -2188,9 +2186,8 @@ primary : literal ...@@ -2188,9 +2186,8 @@ primary : literal
bodystmt bodystmt
keyword_end keyword_end
{ {
SET_BEG_LINENO($<num>2);
$$ = new_sclass(p, $4, $8); $$ = new_sclass(p, $4, $8);
CLEAR_BEG_LINENO(); SET_LINENO($$, $<num>2);
local_resume(p, $<nd>7->car); local_resume(p, $<nd>7->car);
p->in_def = $<num>5; p->in_def = $<num>5;
p->in_single = (int)(intptr_t)$<nd>7->cdr; p->in_single = (int)(intptr_t)$<nd>7->cdr;
...@@ -2208,9 +2205,8 @@ primary : literal ...@@ -2208,9 +2205,8 @@ primary : literal
bodystmt bodystmt
keyword_end keyword_end
{ {
SET_BEG_LINENO($<num>2);
$$ = new_module(p, $3, $5); $$ = new_module(p, $3, $5);
CLEAR_BEG_LINENO(); SET_LINENO($$, $<num>2);
local_resume(p, $<nd>4); local_resume(p, $<nd>4);
} }
| keyword_def fname | keyword_def fname
...@@ -2569,9 +2565,8 @@ brace_block : '{' ...@@ -2569,9 +2565,8 @@ brace_block : '{'
opt_block_param opt_block_param
compstmt '}' compstmt '}'
{ {
SET_BEG_LINENO($<num>2);
$$ = new_block(p,$3,$4); $$ = new_block(p,$3,$4);
CLEAR_BEG_LINENO(); SET_LINENO($$, $<num>2);
local_unnest(p); local_unnest(p);
} }
| keyword_do | keyword_do
...@@ -2582,9 +2577,8 @@ brace_block : '{' ...@@ -2582,9 +2577,8 @@ brace_block : '{'
opt_block_param opt_block_param
compstmt keyword_end compstmt keyword_end
{ {
SET_BEG_LINENO($<num>2);
$$ = new_block(p,$3,$4); $$ = new_block(p,$3,$4);
CLEAR_BEG_LINENO(); SET_LINENO($$, $<num>2);
local_unnest(p); local_unnest(p);
} }
; ;
...@@ -5244,7 +5238,6 @@ mrb_parser_new(mrb_state *mrb) ...@@ -5244,7 +5238,6 @@ mrb_parser_new(mrb_state *mrb)
p->capture_errors = 0; p->capture_errors = 0;
p->lineno = 1; p->lineno = 1;
p->beg_lineno = 0;
p->column = 0; p->column = 0;
#if defined(PARSER_TEST) || defined(PARSER_DEBUG) #if defined(PARSER_TEST) || defined(PARSER_DEBUG)
yydebug = 1; yydebug = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment