Class: Yaparc::Apply

Inherits:
Object
  • Object
show all
Includes:
Parsable
Defined in:
lib/yaparc.rb

Overview

class ApplyParser

Constant Summary

Constants included from Parsable

Parsable::IS_ALPHANUM, Parsable::IS_DIGIT, Parsable::IS_LOWER, Parsable::IS_SPACE, Parsable::IS_WHITESPACE

Instance Attribute Summary

Attributes included from Parsable

#tree

Instance Method Summary collapse

Methods included from Parsable

#eval, included, #parse

Constructor Details

#initialize(parser, &block) ⇒ Apply

Returns a new instance of Apply.



249
250
251
252
253
254
255
256
257
258
# File 'lib/yaparc.rb', line 249

def initialize(parser, &block)
  @parser = lambda do |input|
    case result = parser.parse(input)
    when Result::OK
      Succeed.new(yield(result.value)).parse(result.input)
    else
      Fail.new.parse(input)
    end
  end
end