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
108 def initialize(token_array, offset, locator)
109   @token_array = token_array
110   @offset = offset
111   @locator = locator
112 end

Public Instance Methods

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