aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authoryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-16 01:06:10 +0000
committeryui-knk <yui-knk@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-16 01:06:10 +0000
commitb465633fcc00ec29f4a901fac96ad17bdcddc652 (patch)
tree8f725df7421b5ca5405e294cc88d2b415576431c /parse.y
parentf7c60f8d65807e5122c0d424dac82a94e17b8a5b (diff)
downloadruby-b465633fcc00ec29f4a901fac96ad17bdcddc652.tar.gz
parse.y: Preserve previous line and restore it when read '\n'
* parse.y (parser_params): Add prevline to store previous line. * parse.y (yycompile0): Initialize prevline with 0. * parse.y (parser_nextline): Store previous line on prevline. * parse.y (parser_nextc): Check parser is on EOF or has nextline. Now parser_yylex does not always set lex_p as lex_pend, we should check EOF flag and nextline is set. * parse.y (parser_yylex): Restore previous line, set lex_p and tokp on '\n'. Before this commit, tokp is on the head of next line of '\n' and lex_p is on the tail of next line when next token is '\n'. By this behavior, in some case the last column of NODE_CALL (or NODE_QCALL) is set to the last column of next line. NODE_CALL can be generated via `primary_value call_op operation2 {} opt_paren_args` and opt_paren_args can be none. If none is generated with next token '\n', the last column of none is set to the last column of next line. e.g. : ``` a.b cd.ef ``` The location of NODE_CALL of first line is set to, * Before ``` NODE_CALL (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 6) ``` * After ``` NODE_CALL (line: 1, first_lineno: 1, first_column: 0, last_lineno: 1, last_column: 3) ``` * parse.y (parser_mark): GC mark prevline. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y16
1 files changed, 13 insertions, 3 deletions
diff --git a/parse.y b/parse.y
index f7349496cd..857b62bfe7 100644
--- a/parse.y
+++ b/parse.y
@@ -196,6 +196,7 @@ struct parser_params {
rb_strterm_t *strterm;
VALUE (*gets)(struct parser_params*,VALUE);
VALUE input;
+ VALUE prevline;
VALUE lastline;
VALUE nextline;
const char *pbeg;
@@ -305,6 +306,7 @@ static int parser_yyerror(struct parser_params*, const char*);
#define toksiz (parser->toksiz)
#define tokline (parser->tokline)
#define lex_input (parser->lex.input)
+#define lex_prevline (parser->lex.prevline)
#define lex_lastline (parser->lex.lastline)
#define lex_nextline (parser->lex.nextline)
#define lex_pbeg (parser->lex.pbeg)
@@ -5558,7 +5560,7 @@ yycompile0(VALUE arg)
lex_strterm = 0;
lex_p = lex_pbeg = lex_pend = 0;
- lex_lastline = lex_nextline = 0;
+ lex_prevline = lex_lastline = lex_nextline = 0;
if (parser->error_p) {
VALUE mesg = parser->error_buffer;
if (!mesg) {
@@ -5830,6 +5832,7 @@ parser_nextline(struct parser_params *parser)
lex_pbeg = lex_p = RSTRING_PTR(v);
lex_pend = lex_p + RSTRING_LEN(v);
token_flush(parser);
+ lex_prevline = lex_lastline;
lex_lastline = v;
return 0;
}
@@ -5854,7 +5857,7 @@ parser_nextc(struct parser_params *parser)
{
int c;
- if (UNLIKELY(lex_p == lex_pend)) {
+ if (UNLIKELY((lex_p == lex_pend) || parser->eofp || lex_nextline)) {
if (parser_nextline(parser)) return -1;
}
c = (unsigned char)*lex_p++;
@@ -8300,8 +8303,14 @@ parser_yylex(struct parser_params *parser)
--ruby_sourceline;
lex_nextline = lex_lastline;
case -1: /* EOF no decrement*/
+#ifndef RIPPER
+ if (lex_prevline && !parser->eofp) lex_lastline = lex_prevline;
+ lex_pbeg = RSTRING_PTR(lex_lastline);
+ lex_pend = lex_p = lex_pbeg + RSTRING_LEN(lex_lastline);
+ pushback(1); /* always pushback */
+ parser->tokp = lex_p;
+#else
lex_goto_eol(parser);
-#ifdef RIPPER
if (c != -1) {
parser->tokp = lex_p;
}
@@ -11447,6 +11456,7 @@ parser_mark(void *ptr)
struct parser_params *parser = (struct parser_params*)ptr;
rb_gc_mark(lex_input);
+ rb_gc_mark(lex_prevline);
rb_gc_mark(lex_lastline);
rb_gc_mark(lex_nextline);
rb_gc_mark(ruby_sourcefile_string);