Module: MethodSource::CodeHelpers::IncompleteExpression

Defined in:
lib/method_source/code_helpers.rb

Overview

An exception matcher that matches only subsets of SyntaxErrors that can be fixed by adding more input to the buffer.

Constant Summary collapse

GENERIC_REGEXPS =
[
  /unexpected (\$end|end-of-file|end-of-input|END_OF_FILE)/, # mri, jruby, ruby-2.0, ironruby
  /embedded document meets end of file/, # =begin
  /unterminated (quoted string|string|regexp) meets end of file/, # "quoted string" is ironruby
  /can't find string ".*" anywhere before EOF/, # rbx and jruby
  /missing 'end' for/, /expecting kWHEN/ # rbx
]
RBX_ONLY_REGEXPS =
[
  /expecting '[})\]]'(?:$|:)/, /expecting keyword_end/
]

Class Method Summary collapse

Class Method Details

.===(ex) ⇒ Object


137
138
139
140
141
142
143
144
145
146
147
# File 'lib/method_source/code_helpers.rb', line 137

def self.===(ex)
  return false unless SyntaxError === ex
  case ex.message
  when *GENERIC_REGEXPS
    true
  when *RBX_ONLY_REGEXPS
    rbx?
  else
    false
  end
end

.rbx?Boolean


149
150
151
# File 'lib/method_source/code_helpers.rb', line 149

def self.rbx?
  RbConfig::CONFIG['ruby_install_name'] == 'rbx'
end