Class: Lex::Token

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lex/token.rb

Overview

Used to represent the tokens produced

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, &action) ⇒ Token

Returns a new instance of Token.



16
17
18
19
20
21
# File 'lib/lex/token.rb', line 16

def initialize(name, value, &action)
  @name        = name
  @value       = value
  @action      = action
  @source_line = SourceLine.new
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



12
13
14
# File 'lib/lex/token.rb', line 12

def action
  @action
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/lex/token.rb', line 10

def name
  @name
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/lex/token.rb', line 10

def value
  @value
end

Instance Method Details

#to_arySymbol, ...

Return this token as array of values

Returns:

  • (Symbol, String, Integer, Integer)


33
34
35
# File 'lib/lex/token.rb', line 33

def to_ary
  [name, value, line, column]
end

#to_sObject Also known as: inspect

Return a string representation

Returns:

  • String



42
43
44
# File 'lib/lex/token.rb', line 42

def to_s
  "Lex::Token(#{to_ary.join(',')})"
end

#update_line(line, column) ⇒ Object



23
24
25
26
# File 'lib/lex/token.rb', line 23

def update_line(line, column)
  @source_line.line = line
  @source_line.column = column
end