Class: CaptureSource

Inherits:
Parslet::Atoms::Capture
  • Object
show all
Defined in:
lib/nose/parser.rb

Overview

Parslet DSL extension for capturing the input source

Instance Method Summary collapse

Instance Method Details

#apply(source, context, consume_all) ⇒ Object

Ugly hack to capture the source string that was parsed



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nose/parser.rb', line 10

def apply(source, context, consume_all)
  before = source.instance_variable_get(:@str).rest
  success, value = result = super(source, context, consume_all)
  if success
    # Save the portion of the source string
    after = source.instance_variable_get(:@str).rest
    source_str = before[0..(before.length - after.length - 1)]
    value[(name.to_s + '_source').to_sym] = source_str
  end

  result
end