Class: Yaparc::ManyOne
Overview
class ManyOne
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(parser, identity = []) ⇒ ManyOne
constructor
A new instance of ManyOne.
Methods included from Parsable
Constructor Details
#initialize(parser, identity = []) ⇒ ManyOne
Returns a new instance of ManyOne.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/yaparc.rb', line 333 def initialize(parser, identity = []) @parser = lambda do |input| Seq.new(parser, Many.new(parser, identity)) do |head, tail| case head when ::String if tail.instance_of?(::String) head + tail else raise "Incompatible type: head => #{head}, tail => #{tail}" end when ::Array if tail.instance_of?(Array) head + tail else raise "Incompatible type: head => #{head}, tail => #{tail}" end when ::Hash if tail.instance_of?(Hash) head.merge(tail) else raise "Incompatible type: head => #{head}, tail => #{tail}" end when ::Integer if tail.kind_of?(Integer) head + tail else raise "Incompatible type: head => #{head}, tail => #{tail}" end else raise "Incompatible type: head => #{head}" end #head + tail end end end |