Class: Yaparc::Alt
Overview
of Seq
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
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.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/yaparc.rb', line 181 def initialize(*parsers) @parser = lambda do |input| final_result = Result::Fail.new(:input => input) parsers.each do |parser| case result = parser.parse(input) when Result::Fail next # when Result::Error # raise # 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 |