Class: SyntaxSuggest::RipperErrors

Inherits:
Ripper show all
Defined in:
lib/syntax_suggest/ripper_errors.rb

Overview

Capture parse errors from Ripper

Prism returns the errors with their messages, but Ripper does not. To get them we must make a custom subclass.

Example:

puts RipperErrors.new(" def foo").call.errors
# => ["syntax error, unexpected end-of-input, expecting ';' or '\\n'"]

Constant Summary

Constants inherited from Ripper

Ripper::EVENTS, Ripper::PARSER_EVENTS, Ripper::SCANNER_EVENTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Ripper

lex, parse, sexp, sexp_raw, slice, token_match, tokenize

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



14
15
16
# File 'lib/syntax_suggest/ripper_errors.rb', line 14

def errors
  @errors
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
# File 'lib/syntax_suggest/ripper_errors.rb', line 30

def call
  @run_once ||= begin
    @errors = []
    parse
    true
  end
  self
end

#on_parse_error(msg) ⇒ Object Also known as: on_alias_error, on_assign_error, on_class_name_error, on_param_error, compile_error

Comes from ripper, called on every parse error, msg is a string



19
20
21
22
# File 'lib/syntax_suggest/ripper_errors.rb', line 19

def on_parse_error(msg)
  @errors ||= []
  @errors << msg
end