Class: Yaparc::Identifier
- Inherits:
-
Object
- Object
- Yaparc::Identifier
- Includes:
- Parsable
- Defined in:
- lib/yaparc/identifier.rb
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 Method Summary collapse
-
#initialize(regex: nil, exclude: nil) ⇒ Identifier
constructor
A new instance of Identifier.
Methods included from Parsable
Constructor Details
#initialize(regex: nil, exclude: nil) ⇒ Identifier
Returns a new instance of Identifier.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/yaparc/identifier.rb', line 10 def initialize(regex: nil, exclude: nil) identifier_regex = ::Yaparc::Regex.new(regex || IDENTIFIER_REGEX) tokenizer = Tokenize.new(identifier_regex) unless exclude @parser = proc { tokenizer } return end @parser = lambda do |input| keyword_parsers = exclude.map { |keyword| Yaparc::String.new(keyword) } case result = Yaparc::Alt.new(*keyword_parsers).parse(input) when Yaparc::OK Yaparc::FailParser.new else # Fail or Error tokenizer end end end |