Class: SPARQL::Grammar::Lexer::Token
- Inherits:
-
Object
- Object
- SPARQL::Grammar::Lexer::Token
- Defined in:
- lib/sparql/grammar/lexer.rb
Overview
Represents a lexer token.
Instance Attribute Summary (collapse)
-
- (Integer) lineno
readonly
The line number where the token was encountered.
-
- (Hash) options
readonly
Any additional options for the token.
-
- (Symbol) type
readonly
The token’s symbol type.
-
- (Object) value
readonly
The token’s value.
Instance Method Summary (collapse)
-
- (Boolean) ===(value)
Returns `true` if the given `value` matches either the type or value of this token.
-
- (Object) [](key)
Returns the attribute named by `key`.
-
- (Token) initialize(type, value = nil, options = {})
constructor
Initializes a new token instance.
-
- (String) inspect
Returns a developer-friendly representation of this token.
-
- (Object) representation
Returns type, if not nil, otherwise value.
-
- (Array) to_a
Returns an array representation of this token.
-
- (Hash) to_hash
Returns a hash table representation of this token.
Constructor Details
- (Token) initialize(type, value = nil, options = {})
Initializes a new token instance.
468 469 470 471 472 |
# File 'lib/sparql/grammar/lexer.rb', line 468 def initialize(type, value = nil, = {}) @type, @value = (type ? type.to_s.to_sym : nil), value @options = .dup @lineno = @options.delete(:lineno) end |
Instance Attribute Details
- (Integer) lineno (readonly)
The line number where the token was encountered.
490 491 492 |
# File 'lib/sparql/grammar/lexer.rb', line 490 def lineno @lineno end |
- (Hash) options (readonly)
Any additional options for the token.
496 497 498 |
# File 'lib/sparql/grammar/lexer.rb', line 496 def @options end |
- (Symbol) type (readonly)
The token’s symbol type.
478 479 480 |
# File 'lib/sparql/grammar/lexer.rb', line 478 def type @type end |
- (Object) value (readonly)
The token’s value.
484 485 486 |
# File 'lib/sparql/grammar/lexer.rb', line 484 def value @value end |
Instance Method Details
- (Boolean) ===(value)
Returns `true` if the given `value` matches either the type or value of this token.
524 525 526 527 528 529 530 |
# File 'lib/sparql/grammar/lexer.rb', line 524 def ===(value) case value when Symbol then value == @type when ::String then value.to_s == @value.to_s else value == @value end end |
- (Object) [](key)
Returns the attribute named by `key`.
503 504 505 506 507 508 509 510 |
# File 'lib/sparql/grammar/lexer.rb', line 503 def [](key) key = key.to_s.to_sym unless key.is_a?(Integer) || key.is_a?(Symbol) case key when 0, :type then @type when 1, :value then @value else nil end end |
- (String) inspect
Returns a developer-friendly representation of this token.
558 559 560 |
# File 'lib/sparql/grammar/lexer.rb', line 558 def inspect to_hash.inspect end |
- (Object) representation
Returns type, if not nil, otherwise value
542 543 544 |
# File 'lib/sparql/grammar/lexer.rb', line 542 def representation @type ? @type : @value end |
- (Array) to_a
Returns an array representation of this token.
550 551 552 |
# File 'lib/sparql/grammar/lexer.rb', line 550 def to_a [@type, @value] end |
- (Hash) to_hash
Returns a hash table representation of this token.
536 537 538 |
# File 'lib/sparql/grammar/lexer.rb', line 536 def to_hash {:type => @type, :value => @value} end |