Class: Puppet::Pops::Parser::LexerSupport::TokenValue
- Inherits:
-
Puppet::Pops::Parser::Locatable
- Object
- Puppet::Pops::Parser::Locatable
- Puppet::Pops::Parser::LexerSupport::TokenValue
- 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
- #locator ⇒ Object readonly
- #offset ⇒ Object readonly
- #token_array ⇒ Object readonly
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(token_array, offset, locator) ⇒ TokenValue
constructor
A new instance of TokenValue.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(token_array, offset, locator) ⇒ TokenValue
Returns a new instance of TokenValue.
71 72 73 74 75 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 71 def initialize(token_array, offset, locator) @token_array = token_array @offset = offset @locator = locator end |
Instance Attribute Details
#locator ⇒ Object (readonly)
69 70 71 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 69 def locator @locator end |
#offset ⇒ Object (readonly)
68 69 70 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 68 def offset @offset end |
#token_array ⇒ Object (readonly)
67 68 69 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 67 def token_array @token_array end |
Instance Method Details
#[](key) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 81 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 |
#length ⇒ Object
77 78 79 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 77 def length @token_array[2] end |
#to_s ⇒ Object
102 103 104 105 106 107 |
# File 'lib/puppet/pops/parser/lexer_support.rb', line 102 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 |