Class: RLTK::Token
Overview
The Token class is used to represent the output of a RLTK::Lexer and the input of a RLTK::Parser.
Instance Attribute Summary collapse
-
#position ⇒ StreamPosition
readonly
StreamPosition object associated with this token.
- #type ⇒ Symbol readonly
- #value ⇒ Symbol readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares one token to another.
-
#initialize(type, value = nil, position = nil) ⇒ Token
constructor
Instantiates a new Token object with the values specified.
-
#to_s ⇒ String
String representing the tokens type and value.
Constructor Details
#initialize(type, value = nil, position = nil) ⇒ Token
Instantiates a new Token object with the values specified.
65 66 67 68 69 70 |
# File 'lib/rltk/token.rb', line 65 def initialize(type, value = nil, position = nil) @type = type @value = value @position = position end |
Instance Attribute Details
#position ⇒ StreamPosition (readonly)
Returns StreamPosition object associated with this token.
58 59 60 |
# File 'lib/rltk/token.rb', line 58 def position @position end |
#type ⇒ Symbol (readonly)
52 53 54 |
# File 'lib/rltk/token.rb', line 52 def type @type end |
#value ⇒ Symbol (readonly)
55 56 57 |
# File 'lib/rltk/token.rb', line 55 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Compares one token to another. This only tests the token’s type and value and not the location of the token in its source.
78 79 80 |
# File 'lib/rltk/token.rb', line 78 def ==(other) self.type == other.type and self.value == other.value end |
#to_s ⇒ String
Returns String representing the tokens type and value.
83 84 85 86 87 88 89 |
# File 'lib/rltk/token.rb', line 83 def to_s if value "#{self.type}(#{self.value})" else self.type.to_s end end |