Class: Yaparc::ZeroOne

Inherits:
Object
  • Object
show all
Includes:
Parsable
Defined in:
lib/yaparc.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 Attribute Summary

Attributes included from Parsable

#tree

Instance Method Summary collapse

Methods included from Parsable

#parse

Constructor Details

#initialize(parser, identity = []) ⇒ ZeroOne

Returns a new instance of ZeroOne.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/yaparc.rb', line 83

def initialize(parser, identity = [])
  @parser = lambda do |input|
    case result = parser.parse(input)
    when Result::Fail
      Result::OK.new(:value => identity, :input => input)
#          Succeed.new(identity)
    when Result::Error
      Result::Error.new(:value => result.value, :input => result.input)
    when Result::OK
      result
    else
      raise
    end
  end
end