Class: SyntaxErrorSearch::WhoDisSyntaxError

Inherits:
Ripper
  • Object
show all
Defined in:
lib/syntax_search/who_dis_syntax_error.rb

Overview

Determines what type of syntax error is in the source

Example:

puts WhoDisSyntaxError.new("def foo;").call.error_symbol
# => :missing_end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



11
12
13
# File 'lib/syntax_search/who_dis_syntax_error.rb', line 11

def error
  @error
end

#error_symbolObject (readonly)

Returns the value of attribute error_symbol.



11
12
13
# File 'lib/syntax_search/who_dis_syntax_error.rb', line 11

def error_symbol
  @error_symbol
end

#run_onceObject (readonly)

Returns the value of attribute run_once.



11
12
13
# File 'lib/syntax_search/who_dis_syntax_error.rb', line 11

def run_once
  @run_once
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
# File 'lib/syntax_search/who_dis_syntax_error.rb', line 13

def call
  @run_once ||= begin
    parse
    true
  end
  self
end

#on_parse_error(msg) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/syntax_search/who_dis_syntax_error.rb', line 21

def on_parse_error(msg)
  @error = msg
  if @error.match?(/unexpected end-of-input/)
    @error_symbol = :missing_end
  elsif @error.match?(/unexpected `end'/) || @error.match?(/expecting end-of-input/)
    @error_symbol = :unmatched_end
  else
    @error_symbol = :nope
  end
end