Class: RLTK::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/rltk/token.rb

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)

Instance Method Summary (collapse)

Constructor Details

- (Token) initialize(type, value = nil, position = nil)

Instantiates a new Token object with the values specified.



64
65
66
67
68
69
# File 'lib/rltk/token.rb', line 64

def initialize(type, value = nil, position = nil)
	@type	= type
	@value	= value
	
	@position	= position
end

Instance Attribute Details

- (StreamPosition) position (readonly)



57
58
59
# File 'lib/rltk/token.rb', line 57

def position
  @position
end

- (Symbol) type (readonly)



51
52
53
# File 'lib/rltk/token.rb', line 51

def type
  @type
end

- (Symbol) value (readonly)



54
55
56
# File 'lib/rltk/token.rb', line 54

def value
  @value
end

Instance Method Details

- (Boolean) ==(other)

Compares one token to another. This only tests the token's type and value and not the location of the token in its source.



77
78
79
# File 'lib/rltk/token.rb', line 77

def ==(other)
	self.type == other.type and self.value == other.value
end

- (String) to_s



82
83
84
85
86
87
88
# File 'lib/rltk/token.rb', line 82

def to_s
	if value
		"#{self.type}(#{self.value})"
	else
		self.type.to_s
	end
end