1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Bug #18962] Do not read again once reached EOF

`Ripper::Lexer#parse` re-parses the source code with syntax errors
when `raise_errors: false`.

Co-Authored-By: tompng <tomoyapenguin@gmail.com>
This commit is contained in:
Nobuyoshi Nakada 2022-08-11 22:24:47 +09:00
parent 803a072630
commit 844a0edbae
Notes: git 2022-08-12 15:58:38 +09:00
2 changed files with 15 additions and 0 deletions

View file

@ -9299,6 +9299,7 @@ parser_yylex(struct parser_params *p)
case '\004': /* ^D */
case '\032': /* ^Z */
case -1: /* end of script. */
p->eofp = 1;
return 0;
/* white spaces */

View file

@ -100,6 +100,20 @@ class TestRipper::Lexer < Test::Unit::TestCase
assert_equal expect, Ripper.lex(src).map {|e| e[1]}
end
def test_end_of_script_char
all_assertions do |all|
["a", %w"[a ]", %w"{, }", "if"].each do |src, append|
expected = Ripper.lex(src).map {|e| e[1]}
["\0b", "\4b", "\32b"].each do |eof|
c = "#{src}#{eof}#{append}"
all.for(c) do
assert_equal expected, Ripper.lex(c).map {|e| e[1]}
end
end
end
end
end
def test_slice
assert_equal "string\#{nil}\n",
Ripper.slice(%(<<HERE\nstring\#{nil}\nHERE), "heredoc_beg .*? nl $(.*?) heredoc_end", 1)