Class: Puppet::Pops::Parser::LexerSupport::TokenValue

Inherits:
Puppet::Pops::Parser::Locatable show all
Defined in:
lib/puppet/pops/parser/lexer_support.rb

Overview

A TokenValue keeps track of the token symbol, the lexed text for the token, its length and its position in its source container. There is a cost associated with computing the line and position on line information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_array, offset, locator) ⇒ TokenValue

Returns a new instance of TokenValue.



106
107
108
109
110
# File 'lib/puppet/pops/parser/lexer_support.rb', line 106

def initialize(token_array, offset, locator)
  @token_array = token_array
  @offset = offset
  @locator = locator
end

Instance Attribute Details

#locatorObject (readonly)



104
105
106
# File 'lib/puppet/pops/parser/lexer_support.rb', line 104

def locator
  @locator
end

#offsetObject (readonly)



103
104
105
# File 'lib/puppet/pops/parser/lexer_support.rb', line 103

def offset
  @offset
end

#token_arrayObject (readonly)



102
103
104
# File 'lib/puppet/pops/parser/lexer_support.rb', line 102

def token_array
  @token_array
end

Instance Method Details

#[](key) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/puppet/pops/parser/lexer_support.rb', line 116

def [](key)
  case key
  when :value
    @token_array[1]
  when :file
    @locator.file
  when :line
    @locator.line_for_offset(@offset)
  when :pos
    @locator.pos_on_line(@offset)
  when :length
    @token_array[2]
  when :locator
    @locator
  when :offset
    @offset
  else
    nil
  end
end

#lengthObject



112
113
114
# File 'lib/puppet/pops/parser/lexer_support.rb', line 112

def length
  @token_array[2]
end

#to_sObject



137
138
139
140
141
142
# File 'lib/puppet/pops/parser/lexer_support.rb', line 137

def to_s
  # This format is very compact and is intended for debugging output from racc parsser in
  # debug mode. If this is made more elaborate the output from a debug run becomes very hard to read.
  #
  "'#{self[:value]} #{@token_array[0]}'"
end