mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: adjust here-doc error token
* parse.y (here_document): adjust token to the here-doc identifier in compile_error when a here-document misses the closing identifier.
This commit is contained in:
parent
b0e2b7a5ff
commit
92ecf58b1e
2 changed files with 14 additions and 7 deletions
11
parse.y
11
parse.y
|
@ -7005,9 +7005,9 @@ heredoc_restore(struct parser_params *p, rb_strterm_heredoc_t *here)
|
|||
p->lex.pbeg = RSTRING_PTR(line);
|
||||
p->lex.pend = p->lex.pbeg + RSTRING_LEN(line);
|
||||
p->lex.pcur = p->lex.pbeg + here->offset + here->length + here->quote;
|
||||
p->lex.ptok = p->lex.pbeg + here->offset - here->quote;
|
||||
p->heredoc_end = p->ruby_sourceline;
|
||||
p->ruby_sourceline = (int)here->sourceline;
|
||||
token_flush(p);
|
||||
if (p->eofp) p->lex.nextline = Qnil;
|
||||
p->eofp = 0;
|
||||
}
|
||||
|
@ -7238,8 +7238,6 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
|
|||
|
||||
if ((c = nextc(p)) == -1) {
|
||||
error:
|
||||
compile_error(p, "can't find string \"%.*s\" anywhere before EOF",
|
||||
(int)len, eos);
|
||||
#ifdef RIPPER
|
||||
if (!has_delayed_token(p)) {
|
||||
dispatch_scan_event(p, tSTRING_CONTENT);
|
||||
|
@ -7264,8 +7262,10 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
|
|||
}
|
||||
lex_goto_eol(p);
|
||||
#endif
|
||||
restore:
|
||||
heredoc_restore(p, &p->lex.strterm->u.heredoc);
|
||||
compile_error(p, "can't find string \"%.*s\" anywhere before EOF",
|
||||
(int)len, eos);
|
||||
token_flush(p);
|
||||
p->lex.strterm = 0;
|
||||
SET_LEX_STATE(EXPR_END);
|
||||
return tSTRING_END;
|
||||
|
@ -7283,7 +7283,9 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
|
|||
}
|
||||
else if (whole_match_p(p, eos, len, indent)) {
|
||||
dispatch_heredoc_end(p);
|
||||
restore:
|
||||
heredoc_restore(p, &p->lex.strterm->u.heredoc);
|
||||
token_flush(p);
|
||||
p->lex.strterm = 0;
|
||||
SET_LEX_STATE(EXPR_END);
|
||||
return tSTRING_END;
|
||||
|
@ -7379,6 +7381,7 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
|
|||
yylval.val, str);
|
||||
#endif
|
||||
heredoc_restore(p, &p->lex.strterm->u.heredoc);
|
||||
token_flush(p);
|
||||
p->lex.strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0);
|
||||
set_yylval_str(str);
|
||||
#ifndef RIPPER
|
||||
|
|
|
@ -120,17 +120,21 @@ class TestRipper::Lexer < Test::Unit::TestCase
|
|||
message = proc {result.pretty_inspect}
|
||||
expected = [
|
||||
[[1, 0], :on_heredoc_beg, "<<A", state(:EXPR_BEG)],
|
||||
[[1, 2], :compile_error, "A", state(:EXPR_BEG), "can't find string \"A\" anywhere before EOF"],
|
||||
[[1, 3], :on_period, ".", state(:EXPR_DOT)],
|
||||
[[1, 4], :on_ident, "upcase", state(:EXPR_ARG)],
|
||||
[[1, 10], :on_nl, "\n", state(:EXPR_BEG)],
|
||||
[[1, 11], :compile_error, "", state(:EXPR_BEG), "can't find string \"A\" anywhere before EOF"],
|
||||
]
|
||||
pos = 0
|
||||
expected.each_with_index do |ex, i|
|
||||
s = result[i]
|
||||
assert_equal ex, s.to_a, message
|
||||
assert_equal pos, s.pos[1], message
|
||||
pos += s.tok.bytesize
|
||||
if pos > s.pos[1]
|
||||
assert_equal pos, s.pos[1] + s.tok.bytesize, message
|
||||
else
|
||||
assert_equal pos, s.pos[1], message
|
||||
pos += s.tok.bytesize
|
||||
end
|
||||
end
|
||||
assert_equal pos, code.bytesize
|
||||
assert_equal expected.size, result.size
|
||||
|
|
Loading…
Reference in a new issue