Class: Yaparc::Apply

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

Constant Summary

Constants included from Parsable

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

Instance Method Summary collapse

Methods included from Parsable

#parse

Constructor Details

#initialize(parser) ⇒ Apply

Returns a new instance of Apply.



7
8
9
10
11
12
13
14
15
16
# File 'lib/yaparc/apply.rb', line 7

def initialize(parser)
  @parser = lambda do |input|
    result = parser.parse(input)
    if result.instance_of?(OK)
      Succeed.new(yield(result.value)).parse(result.input)
    else
      FailParser.new.parse(input)
    end
  end
end