Class: Yaparc::Identifier
Overview
Refer to www.cs.nott.ac.uk/~gmh/monparsing.pdf, p.23
Constant Summary collapse
- IDENTIFIER_REGEX =
/\A[a-zA-Z_]+[a-zA-Z0-9_]*/
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(options = {}) ⇒ Identifier
constructor
A new instance of Identifier.
Methods included from Parsable
Constructor Details
#initialize(options = {}) ⇒ Identifier
Returns a new instance of Identifier.
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/yaparc.rb', line 464 def initialize( = {}) identifier_regex = if regex = [:regex] ::Yaparc::Regex.new(regex) else ::Yaparc::Regex.new(IDENTIFIER_REGEX) end tokenizer = Tokenize.new(identifier_regex) if exclude = [:exclude] @parser = lambda do |input| keyword_parsers = exclude.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 tokenizer end end else @parser = lambda do |input| tokenizer end end end |