Class: SyntaxSuggest::RipperErrors
- Inherits:
-
Ripper
- Object
- Ripper
- SyntaxSuggest::RipperErrors
- 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'"]
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #call ⇒ Object
-
#on_parse_error(msg) ⇒ Object
(also: #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.
Instance Attribute Details
#errors ⇒ Object (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
#call ⇒ Object
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 |