summaryrefslogtreecommitdiffhomepage
path: root/src/parse.y
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-01-30 03:53:03 -0800
committerYukihiro "Matz" Matsumoto <[email protected]>2014-01-30 03:53:03 -0800
commit5815ac4fed1403bbf2319e5466fe53d1984c1fec (patch)
tree533a719be0e5258ee5ca4ffb430338a4f899b5db /src/parse.y
parentaa08158f67d8119ad5b68dafc4e58613fb839767 (diff)
parent36e09250539b695b7558acaede0d961a89aa47ec (diff)
downloadmruby-5815ac4fed1403bbf2319e5466fe53d1984c1fec.tar.gz
mruby-5815ac4fed1403bbf2319e5466fe53d1984c1fec.zip
Merge pull request #1667 from h2so5/backtrace-lineno
more accurate backtrace lineno
Diffstat (limited to 'src/parse.y')
-rw-r--r--src/parse.y52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/parse.y b/src/parse.y
index be73ef95a..645cb58e2 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -62,6 +62,9 @@ typedef unsigned int stack_type;
#define CMDARG_LEXPOP() BITSTACK_LEXPOP(p->cmdarg_stack)
#define CMDARG_P() BITSTACK_SET_P(p->cmdarg_stack)
+#define SET_BEG_LINENO(n) (p->beg_lineno = n)
+#define CLEAR_BEG_LINENO() (p->beg_lineno = 0)
+
#define sym(x) ((mrb_sym)(intptr_t)(x))
#define nsym(x) ((node*)(intptr_t)(x))
@@ -120,7 +123,7 @@ cons_gen(parser_state *p, node *car, node *cdr)
c->car = car;
c->cdr = cdr;
- c->lineno = p->lineno;
+ c->lineno = p->beg_lineno ? p->beg_lineno : p->lineno;
c->filename_index = p->current_filename_index;
return c;
}
@@ -2150,7 +2153,11 @@ primary : literal
{
$$ = new_for(p, $2, $5, $8);
}
- | keyword_class cpath superclass
+ | keyword_class
+ {
+ $<num>$ = p->lineno
+ }
+ cpath superclass
{
if (p->in_def || p->in_single)
yyerror(p, "class definition in method body");
@@ -2159,10 +2166,16 @@ primary : literal
bodystmt
keyword_end
{
- $$ = new_class(p, $2, $3, $5);
- local_resume(p, $<nd>4);
+ SET_BEG_LINENO($<num>2);
+ $$ = new_class(p, $3, $4, $6);
+ CLEAR_BEG_LINENO();
+ local_resume(p, $<nd>5);
+ }
+ | keyword_class
+ {
+ $<num>$ = p->lineno
}
- | keyword_class tLSHFT expr
+ tLSHFT expr
{
$<num>$ = p->in_def;
p->in_def = 0;
@@ -2175,12 +2188,18 @@ primary : literal
bodystmt
keyword_end
{
- $$ = new_sclass(p, $3, $7);
- local_resume(p, $<nd>6->car);
- p->in_def = $<num>4;
- p->in_single = (int)(intptr_t)$<nd>6->cdr;
+ SET_BEG_LINENO($<num>2);
+ $$ = new_sclass(p, $4, $8);
+ CLEAR_BEG_LINENO();
+ local_resume(p, $<nd>7->car);
+ p->in_def = $<num>5;
+ p->in_single = (int)(intptr_t)$<nd>7->cdr;
+ }
+ | keyword_module
+ {
+ $<num>$ = p->lineno
}
- | keyword_module cpath
+ cpath
{
if (p->in_def || p->in_single)
yyerror(p, "module definition in method body");
@@ -2189,8 +2208,10 @@ primary : literal
bodystmt
keyword_end
{
- $$ = new_module(p, $2, $4);
- local_resume(p, $<nd>3);
+ SET_BEG_LINENO($<num>2);
+ $$ = new_module(p, $3, $5);
+ CLEAR_BEG_LINENO();
+ local_resume(p, $<nd>4);
}
| keyword_def fname
{
@@ -2543,21 +2564,27 @@ method_call : operation paren_args
brace_block : '{'
{
local_nest(p);
+ $<num>$ = p->lineno;
}
opt_block_param
compstmt '}'
{
+ SET_BEG_LINENO($<num>2);
$$ = new_block(p,$3,$4);
+ CLEAR_BEG_LINENO();
local_unnest(p);
}
| keyword_do
{
local_nest(p);
+ $<num>$ = p->lineno;
}
opt_block_param
compstmt keyword_end
{
+ SET_BEG_LINENO($<num>2);
$$ = new_block(p,$3,$4);
+ CLEAR_BEG_LINENO();
local_unnest(p);
}
;
@@ -5217,6 +5244,7 @@ mrb_parser_new(mrb_state *mrb)
p->capture_errors = 0;
p->lineno = 1;
+ p->beg_lineno = 0;
p->column = 0;
#if defined(PARSER_TEST) || defined(PARSER_DEBUG)
yydebug = 1;