Class: Packrat::LiftOneResultProducer
- Inherits:
-
ResultProducer
- Object
- ResultProducer
- Packrat::LiftOneResultProducer
- 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
- #finalize_result(res) ⇒ Object
-
#initialize(valueIndex, &block) ⇒ LiftOneResultProducer
constructor
A new instance of LiftOneResultProducer.
- #new_result ⇒ Object
- #update_result(res, subres, elem, index, nonhiddenIndex) ⇒ Object
Methods inherited from ResultProducer
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_result ⇒ Object
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 |