Class: Packrat::LiftOneResultProducer

Inherits:
ResultProducer show all
Defined in:
lib/packrat/grammar.rb

Overview

Lift one of the sub-results as the result from parsing a production. Optionally a block can be given. If so the block will get called with the lifted result and can modify it.

Instance Method Summary collapse

Methods inherited from ResultProducer

#production=

Constructor Details

#initialize(valueIndex, &block) ⇒ LiftOneResultProducer

Returns a new instance of LiftOneResultProducer.



267
268
269
270
# File 'lib/packrat/grammar.rb', line 267

def initialize(valueIndex, &block)
  @value_index = valueIndex
  @block = block
end

Instance Method Details

#finalize_result(res) ⇒ Object



275
276
277
# File 'lib/packrat/grammar.rb', line 275

def finalize_result(res)
  @block ? @block.call(res) : res
end

#new_resultObject



271
# File 'lib/packrat/grammar.rb', line 271

def new_result; nil; end

#update_result(res, subres, elem, index, nonhiddenIndex) ⇒ Object



272
273
274
# File 'lib/packrat/grammar.rb', line 272

def update_result(res, subres, elem, index, nonhiddenIndex)
  index == @value_index ? subres : res
end