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:
parent
80d3f21994
commit
1800f3fa5c
2 changed files with 16 additions and 0 deletions
|
@ -31,6 +31,10 @@ class Ripper
|
||||||
raise SyntaxError, r.errors.map(&:message).join(' ;')
|
raise SyntaxError, r.errors.map(&:message).join(' ;')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
until (tokens = r.tokenize).empty?
|
||||||
|
ret.concat(tokens)
|
||||||
|
end
|
||||||
|
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,6 +69,10 @@ class Ripper
|
||||||
raise SyntaxError, r.errors.map(&:message).join(' ;')
|
raise SyntaxError, r.errors.map(&:message).join(' ;')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
until (tokens = r.lex).empty?
|
||||||
|
ret.concat(tokens)
|
||||||
|
end
|
||||||
|
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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) }
|
||||||
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
|
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
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue