Class: Yaparc::Identifier

Inherits:
Object
  • Object
show all
Includes:
Parsable
Defined in:
lib/yaparc.rb

Overview

Constant Summary collapse

@@identifier_regex =
::Yaparc::Regex.new(/\A[a-zA-Z_]+[a-zA-Z0-9_]*/)

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

#tree

Instance Method Summary collapse

Methods included from Parsable

#eval, included

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