class RLTK::Token
The Token
class is used to represent the output of a RLTK::Lexer
and the input of a RLTK::Parser
.
Attributes
@return [StreamPosition] StreamPosition
object associated with this token.
@return [Symbol]
@return [Symbol]
Public Class Methods
Instantiates a new Token
object with the values specified.
@param [Symbol] type A symbol representing the type of this Token
. @param [Object, nil] value A value associated with this token. @param [StreamPosition, nil] position The position of the token in a stream.
# File lib/rltk/token.rb, line 64 def initialize(type, value = nil, position = nil) @type = type @value = value @position = position end
Public Instance Methods
Compares one token to another. This only tests the token’s type and value and not the location of the token in its source.
@param [Token] other Another Token
to compare to.
@return [Boolean]
# File lib/rltk/token.rb, line 77 def ==(other) self.type == other.type and self.value == other.value end
@return [String] String representing the tokens type and value.
# File lib/rltk/token.rb, line 82 def to_s if value "#{self.type}(#{self.value})" else self.type.to_s end end