Class: RKelly::Token

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Token.



4
5
6
7
8
# File 'lib/rkelly/token.rb', line 4

def initialize(name, value, &transformer)
  @name         = name
  @value        = value
  @transformer  = transformer if transformer
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/rkelly/token.rb', line 3

def name
  @name
end

#rangeObject

Returns the value of attribute range.



3
4
5
# File 'lib/rkelly/token.rb', line 3

def range
  @range
end

#transformerObject

Returns the value of attribute transformer.



3
4
5
# File 'lib/rkelly/token.rb', line 3

def transformer
  @transformer
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/rkelly/token.rb', line 3

def value
  @value
end

Instance Method Details

#lineObject

For backwards compatibility



11
12
13
# File 'lib/rkelly/token.rb', line 11

def line
  @range.from.line
end

#to_racc_tokenObject



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

def to_racc_token
  if @transformer
    @name, @value = @transformer.call(@name, @value)
    @transformer = nil
  end
  [@name, @value]
end

#to_sObject



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

def to_s
  return "#{self.name}: #{self.value}"
end