Class: Yaparc::Identifier
Overview
Refer to www.cs.nott.ac.uk/~gmh/monparsing.pdf, p.23
Constant Summary collapse
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(*keywords) ⇒ Identifier
constructor
A new instance of Identifier.
- #parse(input) ⇒ Object
Methods included from Parsable
Constructor Details
#initialize(*keywords) ⇒ Identifier
Returns a new instance of Identifier.
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/yaparc.rb', line 427 def initialize(*keywords) if keywords == [] @parser = lambda do |input| Tokenize.new(@@identifier_regex) end else @parser = lambda do |input| keyword_parsers = keywords.map {|keyword| Yaparc::String.new(keyword)} case result = Yaparc::Alt.new(*keyword_parsers).parse(input) when Yaparc::Result::OK Yaparc::Fail.new else # Result::Fail or Result::Error Tokenize.new(@@identifier_regex) end end end end |
Instance Method Details
#parse(input) ⇒ Object
445 446 447 |
# File 'lib/yaparc.rb', line 445 def parse(input) @parser.call(input).parse(input) end |