123456789_123456789_123456789_123456789_123456789_

Class: SyntaxSuggest::RipperErrors

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Ripper
Instance Chain:
self, Ripper
Inherits: Ripper
  • Object
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

Instance Method Summary

Instance Attribute Details

#errors (readonly)

[ GitHub ]

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

attr_reader :errors

Instance Method Details

#call

[ GitHub ]

  
# File 'lib/syntax_suggest/ripper_errors.rb', line 30

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

#compile_error(msg)

Alias for #on_parse_error.

[ GitHub ]

  
# File 'lib/syntax_suggest/ripper_errors.rb', line 28

alias_method :compile_error, :on_parse_error

#on_alias_error(msg)

Alias for #on_parse_error.

[ GitHub ]

  
# File 'lib/syntax_suggest/ripper_errors.rb', line 24

alias_method :on_alias_error, :on_parse_error

#on_assign_error(msg)

Alias for #on_parse_error.

[ GitHub ]

  
# File 'lib/syntax_suggest/ripper_errors.rb', line 25

alias_method :on_assign_error, :on_parse_error

#on_class_name_error(msg)

Alias for #on_parse_error.

[ GitHub ]

  
# File 'lib/syntax_suggest/ripper_errors.rb', line 26

alias_method :on_class_name_error, :on_parse_error

#on_param_error(msg)

Alias for #on_parse_error.

[ GitHub ]

  
# File 'lib/syntax_suggest/ripper_errors.rb', line 27

alias_method :on_param_error, :on_parse_error

#on_parse_error(msg) 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

[ GitHub ]

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

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