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



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/method_source/code_helpers.rb', line 160

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

Returns:

  • (Boolean)


172
173
174
# File 'lib/method_source/code_helpers.rb', line 172

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