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

Ripper.{lex,tokenize} return full tokens even if syntax error

yet another implements [Feature #17276]
This commit is contained in:
Nobuhiro IMAI 2020-11-19 23:19:08 +09:00 committed by Nobuyoshi Nakada
parent 80d3f21994
commit 1800f3fa5c
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 16 additions and 0 deletions

View file

@ -31,6 +31,10 @@ class Ripper
raise SyntaxError, r.errors.map(&:message).join(' ;')
end
until (tokens = r.tokenize).empty?
ret.concat(tokens)
end
ret
end
@ -65,6 +69,10 @@ class Ripper
raise SyntaxError, r.errors.map(&:message).join(' ;')
end
until (tokens = r.lex).empty?
ret.concat(tokens)
end
ret
end

View file

@ -150,4 +150,12 @@ class TestRipper::Lexer < Test::Unit::TestCase
assert_raise(SyntaxError) { Ripper.tokenize('def req(true) end', raise_errors: true) }
assert_raise(SyntaxError) { Ripper.tokenize('def req(true) end', raise_errors: true) }
end
def test_tokenize_with_syntax_error
assert_equal "end", Ripper.tokenize("def req(true) end").last
end
def test_lex_with_syntax_error
assert_equal [[1, 14], :on_kw, "end", state(:EXPR_END)], Ripper.lex("def req(true) end").last
end
end