Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
abd7cad4
Commit
abd7cad4
authored
Aug 29, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjust node lineno of muiti line statements
parent
4b546e2c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
45 deletions
+79
-45
src/parse.y
src/parse.y
+79
-45
No files found.
src/parse.y
View file @
abd7cad4
...
@@ -62,6 +62,7 @@ typedef unsigned int stack_type;
...
@@ -62,6 +62,7 @@ typedef unsigned int stack_type;
#define CMDARG_P() BITSTACK_SET_P(p->cmdarg_stack)
#define CMDARG_P() BITSTACK_SET_P(p->cmdarg_stack)
#define SET_LINENO(c,n) ((c)->lineno = (n))
#define SET_LINENO(c,n) ((c)->lineno = (n))
#define NODE_LINENO(c,n) do {if (n) ((c)->lineno = (n)->lineno);} while (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))
...
@@ -275,8 +276,9 @@ new_scope(parser_state *p, node *body)
...
@@ -275,8 +276,9 @@ new_scope(parser_state *p, node *body)
static node*
static node*
new_begin(parser_state *p, node *body)
new_begin(parser_state *p, node *body)
{
{
if (body)
if (body)
{
return list2((node*)NODE_BEGIN, body);
return list2((node*)NODE_BEGIN, body);
}
return cons((node*)NODE_BEGIN, 0);
return cons((node*)NODE_BEGIN, 0);
}
}
...
@@ -391,14 +393,20 @@ new_self(parser_state *p)
...
@@ -391,14 +393,20 @@ new_self(parser_state *p)
static node*
static node*
new_call(parser_state *p, node *a, mrb_sym b, node *c)
new_call(parser_state *p, node *a, mrb_sym b, node *c)
{
{
return list4((node*)NODE_CALL, a, nsym(b), c);
node *n = list4((node*)NODE_CALL, a, nsym(b), c);
NODE_LINENO(n, a);
return n;
}
}
/* (:fcall self mid args) */
/* (:fcall self mid args) */
static node*
static node*
new_fcall(parser_state *p, mrb_sym b, node *c)
new_fcall(parser_state *p, mrb_sym b, node *c)
{
{
return list4((node*)NODE_FCALL, new_self(p), nsym(b), c);
node *n = new_self(p);
NODE_LINENO(n, c);
n = list4((node*)NODE_FCALL, n, nsym(b), c);
NODE_LINENO(n, c);
return n;
}
}
/* (:super . c) */
/* (:super . c) */
...
@@ -997,25 +1005,27 @@ heredoc_end(parser_state *p)
...
@@ -997,25 +1005,27 @@ heredoc_end(parser_state *p)
const struct vtable *vars;
const struct vtable *vars;
}
}
%token
%token
<num>
keyword_class
keyword_class
keyword_module
keyword_module
keyword_def
keyword_def
keyword_undef
keyword_begin
keyword_begin
keyword_if
keyword_unless
keyword_while
keyword_until
keyword_for
%token
keyword_undef
keyword_rescue
keyword_rescue
keyword_ensure
keyword_ensure
keyword_end
keyword_end
keyword_if
keyword_unless
keyword_then
keyword_then
keyword_elsif
keyword_elsif
keyword_else
keyword_else
keyword_case
keyword_case
keyword_when
keyword_when
keyword_while
keyword_until
keyword_for
keyword_break
keyword_break
keyword_next
keyword_next
keyword_redo
keyword_redo
...
@@ -1155,6 +1165,7 @@ program : {
...
@@ -1155,6 +1165,7 @@ program : {
top_compstmt
top_compstmt
{
{
p->tree = new_scope(p, $2);
p->tree = new_scope(p, $2);
NODE_LINENO(p->tree, $2);
}
}
;
;
...
@@ -1171,6 +1182,7 @@ top_stmts : none
...
@@ -1171,6 +1182,7 @@ top_stmts : none
| top_stmt
| top_stmt
{
{
$$ = new_begin(p, $1);
$$ = new_begin(p, $1);
NODE_LINENO($$, $1);
}
}
| top_stmts terms top_stmt
| top_stmts terms top_stmt
{
{
...
@@ -1202,6 +1214,7 @@ bodystmt : compstmt
...
@@ -1202,6 +1214,7 @@ bodystmt : compstmt
{
{
if ($2) {
if ($2) {
$$ = new_rescue(p, $1, $2, $3);
$$ = new_rescue(p, $1, $2, $3);
NODE_LINENO($$, $1);
}
}
else if ($3) {
else if ($3) {
yywarn(p, "else without rescue is useless");
yywarn(p, "else without rescue is useless");
...
@@ -1234,10 +1247,11 @@ stmts : none
...
@@ -1234,10 +1247,11 @@ stmts : none
| stmt
| stmt
{
{
$$ = new_begin(p, $1);
$$ = new_begin(p, $1);
NODE_LINENO($$, $1);
}
}
| stmts terms stmt
| stmts terms stmt
{
{
$$ = push($1, newline_node($3));
$$ = push($1, newline_node($3));
}
}
| error stmt
| error stmt
{
{
...
@@ -1255,7 +1269,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
...
@@ -1255,7 +1269,7 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
}
}
| stmt modifier_if expr_value
| stmt modifier_if expr_value
{
{
$$ = new_if(p, cond($3), $1, 0);
$$ = new_if(p, cond($3), $1, 0);
}
}
| stmt modifier_unless expr_value
| stmt modifier_unless expr_value
{
{
...
@@ -1887,6 +1901,7 @@ aref_args : none
...
@@ -1887,6 +1901,7 @@ aref_args : none
| args trailer
| args trailer
{
{
$$ = $1;
$$ = $1;
NODE_LINENO($$, $1);
}
}
| args ',' assocs trailer
| args ',' assocs trailer
{
{
...
@@ -1895,6 +1910,7 @@ aref_args : none
...
@@ -1895,6 +1910,7 @@ aref_args : none
| assocs trailer
| assocs trailer
{
{
$$ = cons(new_hash(p, $1), 0);
$$ = cons(new_hash(p, $1), 0);
NODE_LINENO($$, $1);
}
}
;
;
...
@@ -1913,36 +1929,44 @@ opt_call_args : none
...
@@ -1913,36 +1929,44 @@ opt_call_args : none
| args ','
| args ','
{
{
$$ = cons($1,0);
$$ = cons($1,0);
NODE_LINENO($$, $1);
}
}
| args ',' assocs ','
| args ',' assocs ','
{
{
$$ = cons(push($1, new_hash(p, $3)), 0);
$$ = cons(push($1, new_hash(p, $3)), 0);
NODE_LINENO($$, $1);
}
}
| assocs ','
| assocs ','
{
{
$$ = cons(list1(new_hash(p, $1)), 0);
$$ = cons(list1(new_hash(p, $1)), 0);
NODE_LINENO($$, $1);
}
}
;
;
call_args : command
call_args : command
{
{
$$ = cons(list1($1), 0);
$$ = cons(list1($1), 0);
NODE_LINENO($$, $1);
}
}
| args opt_block_arg
| args opt_block_arg
{
{
$$ = cons($1, $2);
$$ = cons($1, $2);
NODE_LINENO($$, $1);
}
}
| assocs opt_block_arg
| assocs opt_block_arg
{
{
$$ = cons(list1(new_hash(p, $1)), $2);
$$ = cons(list1(new_hash(p, $1)), $2);
NODE_LINENO($$, $1);
}
}
| args ',' assocs opt_block_arg
| args ',' assocs opt_block_arg
{
{
$$ = cons(push($1, new_hash(p, $3)), $4);
$$ = cons(push($1, new_hash(p, $3)), $4);
NODE_LINENO($$, $1);
}
}
| block_arg
| block_arg
{
{
$$ = cons(0, $1);
$$ = cons(0, $1);
NODE_LINENO($$, $1);
}
}
;
;
...
@@ -1976,10 +2000,12 @@ opt_block_arg : ',' block_arg
...
@@ -1976,10 +2000,12 @@ opt_block_arg : ',' block_arg
args : arg_value
args : arg_value
{
{
$$ = cons($1, 0);
$$ = cons($1, 0);
NODE_LINENO($$, $1);
}
}
| tSTAR arg_value
| tSTAR arg_value
{
{
$$ = cons(new_splat(p, $2), 0);
$$ = cons(new_splat(p, $2), 0);
NODE_LINENO($$, $2);
}
}
| args ',' arg_value
| args ',' arg_value
{
{
...
@@ -2026,23 +2052,23 @@ primary : literal
...
@@ -2026,23 +2052,23 @@ primary : literal
}
}
| keyword_begin
| keyword_begin
{
{
$<stack>
1
= p->cmdarg_stack;
$<stack>
$
= p->cmdarg_stack;
p->cmdarg_stack = 0;
p->cmdarg_stack = 0;
}
}
bodystmt
bodystmt
keyword_end
keyword_end
{
{
p->cmdarg_stack = $<stack>
1
;
p->cmdarg_stack = $<stack>
2
;
$$ = $3;
$$ = $3;
}
}
| tLPAREN_ARG
| tLPAREN_ARG
{
{
$<stack>
1
= p->cmdarg_stack;
$<stack>
$
= p->cmdarg_stack;
p->cmdarg_stack = 0;
p->cmdarg_stack = 0;
}
}
expr {p->lstate = EXPR_ENDARG;} rparen
expr {p->lstate = EXPR_ENDARG;} rparen
{
{
p->cmdarg_stack = $<stack>
1
;
p->cmdarg_stack = $<stack>
2
;
$$ = $3;
$$ = $3;
}
}
| tLPAREN_ARG {p->lstate = EXPR_ENDARG;} rparen
| tLPAREN_ARG {p->lstate = EXPR_ENDARG;} rparen
...
@@ -2064,10 +2090,12 @@ primary : literal
...
@@ -2064,10 +2090,12 @@ primary : literal
| tLBRACK aref_args ']'
| tLBRACK aref_args ']'
{
{
$$ = new_array(p, $2);
$$ = new_array(p, $2);
NODE_LINENO($$, $2);
}
}
| tLBRACE assoc_list '}'
| tLBRACE assoc_list '}'
{
{
$$ = new_hash(p, $2);
$$ = new_hash(p, $2);
NODE_LINENO($$, $2);
}
}
| keyword_return
| keyword_return
{
{
...
@@ -2122,6 +2150,7 @@ primary : literal
...
@@ -2122,6 +2150,7 @@ primary : literal
keyword_end
keyword_end
{
{
$$ = new_if(p, cond($2), $4, $5);
$$ = new_if(p, cond($2), $4, $5);
SET_LINENO($$, $1);
}
}
| keyword_unless expr_value then
| keyword_unless expr_value then
compstmt
compstmt
...
@@ -2129,18 +2158,21 @@ primary : literal
...
@@ -2129,18 +2158,21 @@ primary : literal
keyword_end
keyword_end
{
{
$$ = new_unless(p, cond($2), $4, $5);
$$ = new_unless(p, cond($2), $4, $5);
SET_LINENO($$, $1);
}
}
| keyword_while {COND_PUSH(1);} expr_value do {COND_POP();}
| keyword_while {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
compstmt
keyword_end
keyword_end
{
{
$$ = new_while(p, cond($3), $6);
$$ = new_while(p, cond($3), $6);
SET_LINENO($$, $1);
}
}
| keyword_until {COND_PUSH(1);} expr_value do {COND_POP();}
| keyword_until {COND_PUSH(1);} expr_value do {COND_POP();}
compstmt
compstmt
keyword_end
keyword_end
{
{
$$ = new_until(p, cond($3), $6);
$$ = new_until(p, cond($3), $6);
SET_LINENO($$, $1);
}
}
| keyword_case expr_value opt_terms
| keyword_case expr_value opt_terms
case_body
case_body
...
@@ -2160,11 +2192,9 @@ primary : literal
...
@@ -2160,11 +2192,9 @@ primary : literal
keyword_end
keyword_end
{
{
$$ = new_for(p, $2, $5, $8);
$$ = new_for(p, $2, $5, $8);
SET_LINENO($$, $1);
}
}
| keyword_class
| keyword_class
{
$<num>$ = p->lineno;
}
cpath superclass
cpath superclass
{
{
if (p->in_def || p->in_single)
if (p->in_def || p->in_single)
...
@@ -2174,14 +2204,11 @@ primary : literal
...
@@ -2174,14 +2204,11 @@ primary : literal
bodystmt
bodystmt
keyword_end
keyword_end
{
{
$$ = new_class(p, $
3, $4, $6
);
$$ = new_class(p, $
2, $3, $5
);
SET_LINENO($$, $
<num>2
);
SET_LINENO($$, $
1
);
local_resume(p, $<nd>
5
);
local_resume(p, $<nd>
4
);
}
}
| keyword_class
| keyword_class
{
$<num>$ = p->lineno;
}
tLSHFT expr
tLSHFT expr
{
{
$<num>$ = p->in_def;
$<num>$ = p->in_def;
...
@@ -2195,16 +2222,13 @@ primary : literal
...
@@ -2195,16 +2222,13 @@ primary : literal
bodystmt
bodystmt
keyword_end
keyword_end
{
{
$$ = new_sclass(p, $
4, $8
);
$$ = new_sclass(p, $
3, $7
);
SET_LINENO($$, $
<num>2
);
SET_LINENO($$, $
1
);
local_resume(p, $<nd>
7
->car);
local_resume(p, $<nd>
6
->car);
p->in_def = $<num>
5
;
p->in_def = $<num>
4
;
p->in_single = (int)(intptr_t)$<nd>
7
->cdr;
p->in_single = (int)(intptr_t)$<nd>
6
->cdr;
}
}
| keyword_module
| keyword_module
{
$<num>$ = p->lineno;
}
cpath
cpath
{
{
if (p->in_def || p->in_single)
if (p->in_def || p->in_single)
...
@@ -2214,42 +2238,50 @@ primary : literal
...
@@ -2214,42 +2238,50 @@ primary : literal
bodystmt
bodystmt
keyword_end
keyword_end
{
{
$$ = new_module(p, $
3, $5
);
$$ = new_module(p, $
2, $4
);
SET_LINENO($$, $
<num>2
);
SET_LINENO($$, $
1
);
local_resume(p, $<nd>
4
);
local_resume(p, $<nd>
3
);
}
}
| keyword_def fname
| keyword_def fname
{
$<stack>$ = p->cmdarg_stack;
p->cmdarg_stack = 0;
}
{
{
p->in_def++;
p->in_def++;
$<nd>$ = local_switch(p);
$<nd>$ = local_switch(p);
$<stack>1 = p->cmdarg_stack;
p->cmdarg_stack = 0;
}
}
f_arglist
f_arglist
bodystmt
bodystmt
keyword_end
keyword_end
{
{
$$ = new_def(p, $2, $4, $5);
$$ = new_def(p, $2, $5, $6);
local_resume(p, $<nd>3);
SET_LINENO($$, $1);
local_resume(p, $<nd>4);
p->in_def--;
p->in_def--;
p->cmdarg_stack = $<stack>
1
;
p->cmdarg_stack = $<stack>
3
;
}
}
| keyword_def singleton dot_or_colon {p->lstate = EXPR_FNAME;} fname
| keyword_def singleton dot_or_colon
{
p->lstate = EXPR_FNAME;
$<stack>$ = p->cmdarg_stack;
p->cmdarg_stack = 0;
}
fname
{
{
p->in_single++;
p->in_single++;
p->lstate = EXPR_ENDFN; /* force for args */
p->lstate = EXPR_ENDFN; /* force for args */
$<nd>$ = local_switch(p);
$<nd>$ = local_switch(p);
$<stack>1 = p->cmdarg_stack;
p->cmdarg_stack = 0;
}
}
f_arglist
f_arglist
bodystmt
bodystmt
keyword_end
keyword_end
{
{
$$ = new_sdef(p, $2, $5, $7, $8);
$$ = new_sdef(p, $2, $5, $7, $8);
SET_LINENO($$, $1);
local_resume(p, $<nd>6);
local_resume(p, $<nd>6);
p->in_single--;
p->in_single--;
p->cmdarg_stack = $<stack>
1
;
p->cmdarg_stack = $<stack>
4
;
}
}
| keyword_break
| keyword_break
{
{
...
@@ -3163,6 +3195,7 @@ assoc_list : none
...
@@ -3163,6 +3195,7 @@ assoc_list : none
assocs : assoc
assocs : assoc
{
{
$$ = list1($1);
$$ = list1($1);
NODE_LINENO($$, $1);
}
}
| assocs ',' assoc
| assocs ',' assoc
{
{
...
@@ -5210,6 +5243,7 @@ parser_yylex(parser_state *p)
...
@@ -5210,6 +5243,7 @@ parser_yylex(parser_state *p)
kw = mrb_reserved_word(tok(p), toklen(p));
kw = mrb_reserved_word(tok(p), toklen(p));
if (kw) {
if (kw) {
enum mrb_lex_state_enum state = p->lstate;
enum mrb_lex_state_enum state = p->lstate;
yylval.num = p->lineno;
p->lstate = kw->state;
p->lstate = kw->state;
if (state == EXPR_FNAME) {
if (state == EXPR_FNAME) {
yylval.id = intern_cstr(kw->name);
yylval.id = intern_cstr(kw->name);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment