Class: Yaparc::ZeroOne

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

Overview

class ZeroOneParser

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, identity = []) ⇒ ZeroOne

Returns a new instance of ZeroOne.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/yaparc.rb', line 105

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

#        AltParser.new(parser, Succeed.new(identity))
#         case result = AltParser.new(parser, Succeed.new(identity)).parse(input)
#         if input.nil? or input.empty?
#           Result::Fail.new(:input => input)
#         else
#           Result::OK.new(:value => input[0..0],:input => input[1..input.length])
#         end

  end
end