class RLTK::Token

The Token class is used to represent the output of a RLTK::Lexer and the input of a RLTK::Parser.

Attributes

position[R]

@return [StreamPosition] StreamPosition object associated with this token.

type[R]

@return [Symbol]

value[R]

@return [Symbol]

Public Class Methods

new(type, value = nil, position = nil) click to toggle source

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

==(other) click to toggle source

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
to_s() click to toggle source

@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