class Puppet::Pops::Parser::LexerSupport::TokenValue

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.

Attributes

locator[R]
offset[R]
token_array[R]

Public Class Methods

new(token_array, offset, locator) click to toggle source
    # File lib/puppet/pops/parser/lexer_support.rb
107 def initialize(token_array, offset, locator)
108   @token_array = token_array
109   @offset = offset
110   @locator = locator
111 end

Public Instance Methods

[](key) click to toggle source
    # File lib/puppet/pops/parser/lexer_support.rb
117 def [](key)
118   case key
119   when :value
120     @token_array[1]
121   when :file
122     @locator.file
123   when :line
124     @locator.line_for_offset(@offset)
125   when :pos
126     @locator.pos_on_line(@offset)
127   when :length
128     @token_array[2]
129   when :locator
130     @locator
131   when :offset
132     @offset
133   else
134     nil
135   end
136 end
length() click to toggle source
    # File lib/puppet/pops/parser/lexer_support.rb
113 def length
114   @token_array[2]
115 end
to_s() click to toggle source
    # File lib/puppet/pops/parser/lexer_support.rb
138 def to_s
139   # This format is very compact and is intended for debugging output from racc parser in
140   # debug mode. If this is made more elaborate the output from a debug run becomes very hard to read.
141   #
142   "'#{self[:value]} #{@token_array[0]}'"
143 end