class DeadEnd::WhoDisSyntaxError
Determines what type of syntax error is in the source
Example:
puts WhoDisSyntaxError.new("def foo;").call.error_symbol # => :missing_end
Attributes
error[R]
run_once[R]
Public Instance Methods
call()
click to toggle source
# File lib/dead_end/who_dis_syntax_error.rb, line 36 def call @run_once ||= begin parse true end self end
error_symbol()
click to toggle source
Return options:
- :missing_end - :unmatched_syntax - :unknown
# File lib/dead_end/who_dis_syntax_error.rb, line 21 def error_symbol call @error_symbol end
on_parse_error(msg)
click to toggle source
# File lib/dead_end/who_dis_syntax_error.rb, line 44 def on_parse_error(msg) return if @error_symbol && @unmatched_symbol @error = msg @unmatched_symbol = :unknown case @error when /unexpected end-of-input/ @error_symbol = :missing_end when /expecting end-of-input/ @unmatched_symbol = :end @error_symbol = :unmatched_syntax when /unexpected .* expecting '(?<unmatched_symbol>.*)'/ @unmatched_symbol = $1.to_sym if $1 @error_symbol = :unmatched_syntax when /unexpected `end'/, # Ruby 2.7 and 3.0 /unexpected end/, # Ruby 2.6 /unexpected keyword_end/i # Ruby 2.5 @error_symbol = :unmatched_syntax else @error_symbol = :unknown end end
unmatched_symbol()
click to toggle source
Return options:
- :end - :| - :} - :unknown
# File lib/dead_end/who_dis_syntax_error.rb, line 31 def unmatched_symbol call @unmatched_symbol end