Class: Dhaka::Token

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

Overview

Represents a portion of the input character stream that is mapped by the tokenizer to a symbol in the grammar. The attribute input_position contains the start index position of the original string input that this token came from. It can be used to report errors by indicating the specific portion of the input where the error occurred.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol_name, value, input_position) ⇒ Token

Returns a new instance of Token.



8
9
10
11
12
# File 'lib/parser/token.rb', line 8

def initialize(symbol_name, value, input_position)
  @symbol_name = symbol_name
  @value = value
  @input_position = input_position
end

Instance Attribute Details

#input_positionObject

Returns the value of attribute input_position.



7
8
9
# File 'lib/parser/token.rb', line 7

def input_position
  @input_position
end

#symbol_nameObject

Returns the value of attribute symbol_name.



7
8
9
# File 'lib/parser/token.rb', line 7

def symbol_name
  @symbol_name
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/parser/token.rb', line 7

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
# File 'lib/parser/token.rb', line 16

def == other
  (symbol_name == other.symbol_name) && (value == other.value)
end

#to_sObject

:nodoc:



13
14
15
# File 'lib/parser/token.rb', line 13

def to_s #:nodoc:
  "#{symbol_name}"
end