summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-02 00:27:25 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-02 16:12:08 +0900
commit3becc4a105bcf873fdc6e83c2a957f73718c5084 (patch)
tree05cdec0078f36a1695dd67eb58bcf30fcb4f9c38 /parse.y
parent1912bf54613f2e60e96a15906be0684a99ac9553 (diff)
downloadruby-3becc4a105bcf873fdc6e83c2a957f73718c5084.tar.gz
[Bug #19291] Rewind to the previous line
When rewinding looking ahead after newline token, also reset the last line string, the pointers to it, and the location, not only the line number.
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y17
1 files changed, 13 insertions, 4 deletions
diff --git a/parse.y b/parse.y
index a6ed829b84..301266c36f 100644
--- a/parse.y
+++ b/parse.y
@@ -7028,6 +7028,14 @@ add_delayed_token(struct parser_params *p, const char *tok, const char *end, int
}
}
+static void
+set_lastline(struct parser_params *p, VALUE v)
+{
+ p->lex.pbeg = p->lex.pcur = RSTRING_PTR(v);
+ p->lex.pend = p->lex.pcur + RSTRING_LEN(v);
+ p->lex.lastline = v;
+}
+
static int
nextline(struct parser_params *p, int set_encoding)
{
@@ -7065,10 +7073,8 @@ nextline(struct parser_params *p, int set_encoding)
p->heredoc_end = 0;
}
p->ruby_sourceline++;
- p->lex.pbeg = p->lex.pcur = RSTRING_PTR(v);
- p->lex.pend = p->lex.pcur + RSTRING_LEN(v);
+ set_lastline(p, v);
token_flush(p);
- p->lex.lastline = v;
return 0;
}
@@ -9850,6 +9856,7 @@ parser_yylex(struct parser_params *p)
/* fall through */
case '\n':
p->token_seen = token_seen;
+ VALUE prevline = p->lex.lastline;
c = (IS_lex_state(EXPR_BEG|EXPR_CLASS|EXPR_FNAME|EXPR_DOT) &&
!IS_lex_state(EXPR_LABELED));
if (c || IS_lex_state_all(EXPR_ARG|EXPR_LABELED)) {
@@ -9887,10 +9894,12 @@ parser_yylex(struct parser_params *p)
default:
p->ruby_sourceline--;
p->lex.nextline = p->lex.lastline;
+ set_lastline(p, prevline);
case -1: /* EOF no decrement*/
lex_goto_eol(p);
if (c != -1) {
- p->lex.ptok = p->lex.pcur;
+ token_flush(p);
+ RUBY_SET_YYLLOC(*p->yylloc);
}
goto normal_newline;
}