class CaptureSource

Parslet DSL extension for capturing the input source

Public Instance Methods

apply(source, context, consume_all) click to toggle source

Ugly hack to capture the source string that was parsed

Calls superclass method
# 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