Class: Yaparc::Alt
Overview
class AltParser
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
Instance Method Summary collapse
-
#initialize(*parsers) ⇒ Alt
constructor
A new instance of Alt.
Methods included from Parsable
Constructor Details
#initialize(*parsers) ⇒ Alt
Returns a new instance of Alt.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/yaparc.rb', line 224 def initialize(*parsers) @parser = lambda do |input| initial_result = Result::OK.new(:input => input) final_result = Result::Fail.new(:input => input) parsers.each do |parser| # case result = parser.parse(initial_result.input) case result = parser.parse(input) when Result::Fail next when Result::Error return Result::Error.new(:value => result.value, :input => result.input) when Result::OK break final_result = result else raise end end final_result end end |