class SyntaxSuggest::RipperErrors
从 Ripper 中捕获解析错误
Prism 会返回带有错误消息的错误,但 Ripper 不会。为了获取它们,我们必须创建一个自定义子类。
示例
puts RipperErrors.new(" def foo").call.errors # => ["syntax error, unexpected end-of-input, expecting ';' or '\\n'"]
属性
Public Instance Methods
Source
# File lib/syntax_suggest/ripper_errors.rb, line 30 def call @run_once ||= begin @errors = [] parse true end self end
Source
# File lib/syntax_suggest/ripper_errors.rb, line 19 def on_parse_error(msg) @errors ||= [] @errors << msg end
来自 ripper,在每次解析错误时调用,msg 是一个字符串