Class: PuppetLint::Lexer::Token
- Inherits:
-
Object
- Object
- PuppetLint::Lexer::Token
- Defined in:
- lib/puppet-lint/lexer/token.rb
Overview
Public: Stores a fragment of the manifest and the information about its location in the manifest.
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Public: Returns the Integer column number of the line of the manifest text where the Token can be found.
-
#line ⇒ Object
readonly
Public: Returns the Integer line number of the manifest text where the Token can be found.
-
#next_code_token ⇒ Object
Public: Gets/sets the next code token (skips whitespace, comments, etc) in the manifest.
-
#next_token ⇒ Object
Public: Gets/sets the next token in the manifest.
-
#prev_code_token ⇒ Object
Public: Gets/sets the previous code tokne (skips whitespace, comments, etc) in the manifest.
-
#prev_token ⇒ Object
Public: Gets/sets the previous token in the manifest.
-
#type ⇒ Object
Public: Returns the Symbol type of the Token.
-
#value ⇒ Object
Public: Returns the String value of the Token.
Instance Method Summary collapse
-
#initialize(type, value, line, column) ⇒ Token
constructor
Public: Initialise a new Token object.
-
#inspect ⇒ Object
Public: Produce a human friendly description of the Token when inspected.
-
#to_manifest ⇒ Object
Public: Produce a Puppet DSL representation of a Token.
Constructor Details
#initialize(type, value, line, column) ⇒ Token
Public: Initialise a new Token object.
type - An upper case Symbol describing the type of Token. value - The String value of the Token. line - The Integer line number where the Token can be found in the
manifest.
column - The Integer number of characters from the start of the line to
the start of the Token.
Returns the instantiated Token.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppet-lint/lexer/token.rb', line 44 def initialize(type, value, line, column) @value = value @type = type @line = line @column = column @next_token = nil @prev_token = nil @next_code_token = nil @prev_code_token = nil end |
Instance Attribute Details
#column ⇒ Object (readonly)
Public: Returns the Integer column number of the line of the manifest text where the Token can be found.
18 19 20 |
# File 'lib/puppet-lint/lexer/token.rb', line 18 def column @column end |
#line ⇒ Object (readonly)
Public: Returns the Integer line number of the manifest text where the Token can be found.
14 15 16 |
# File 'lib/puppet-lint/lexer/token.rb', line 14 def line @line end |
#next_code_token ⇒ Object
Public: Gets/sets the next code token (skips whitespace, comments, etc) in the manifest.
28 29 30 |
# File 'lib/puppet-lint/lexer/token.rb', line 28 def next_code_token @next_code_token end |
#next_token ⇒ Object
Public: Gets/sets the next token in the manifest.
21 22 23 |
# File 'lib/puppet-lint/lexer/token.rb', line 21 def next_token @next_token end |
#prev_code_token ⇒ Object
Public: Gets/sets the previous code tokne (skips whitespace, comments, etc) in the manifest.
32 33 34 |
# File 'lib/puppet-lint/lexer/token.rb', line 32 def prev_code_token @prev_code_token end |
#prev_token ⇒ Object
Public: Gets/sets the previous token in the manifest.
24 25 26 |
# File 'lib/puppet-lint/lexer/token.rb', line 24 def prev_token @prev_token end |
#type ⇒ Object
Public: Returns the Symbol type of the Token.
7 8 9 |
# File 'lib/puppet-lint/lexer/token.rb', line 7 def type @type end |
#value ⇒ Object
Public: Returns the String value of the Token.
10 11 12 |
# File 'lib/puppet-lint/lexer/token.rb', line 10 def value @value end |
Instance Method Details
#inspect ⇒ Object
Public: Produce a human friendly description of the Token when inspected.
Returns a String describing the Token.
59 60 61 |
# File 'lib/puppet-lint/lexer/token.rb', line 59 def inspect "<Token #{@type.inspect} (#{@value}) @#{@line}:#{@column}>" end |
#to_manifest ⇒ Object
Public: Produce a Puppet DSL representation of a Token.
Returns a Puppet DSL String.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/puppet-lint/lexer/token.rb', line 66 def to_manifest case @type when :STRING "\"#{@value}\"" when :SSTRING "'#{@value}'" when :DQPRE "\"#{@value}" when :DQPOST "#{@value}\"" when :VARIABLE if !@prev_code_token.nil? && [:DQPRE, :DQMID].include?(@prev_code_token.type) "${#{@value}}" else "$#{@value}" end when :UNENC_VARIABLE "$#{@value}" when :NEWLINE "\n" when :COMMENT "##{@value}" when :REGEX "/#{@value}/" else @value end end |