Add error_tolerant option to RubyVM::AST

If this option is enabled, SyntaxError is not raised and Node is
returned even if passed script is broken.

[Feature #19013]
This commit is contained in:
yui-knk 2022-09-25 17:53:44 +09:00 committed by Yuichiro Kaneko
parent 7775d14356
commit fbbdbdd891
Notes: git 2022-10-08 17:59:35 +09:00
5 changed files with 50 additions and 20 deletions

View file

@ -565,4 +565,17 @@ dummy
assert_in_out_err(["-e", "def foo; end; pp RubyVM::AbstractSyntaxTree.of(method(:foo)).type"],
"", [":SCOPE"], [])
end
def test_error_tolerant
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
class A
def m
if;
a = 10
end
end
STR
assert_equal(:SCOPE, node.type)
end
end