Class: Yaparc::ZeroOne

Inherits:
Object
  • Object
show all
Includes:
Parsable
Defined in:
lib/yaparc/zero_one.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, identity = []) ⇒ ZeroOne

Returns a new instance of ZeroOne.



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

def initialize(parser, identity = [])
  @parser = lambda do |input|
    case (result = parser.parse(input))
    in Fail
      OK.new(value: identity, input:)
    in Error
      Error.new(value: result.value, input: result.input)
    in OK
      result
    end
  end
end