lib/puppet-lint/data.rb
# Internal: Calculate the positions of all the specified defintion types
# within the `tokens` Array.
#
# Returns an Array of Hashes, each containing:
#   :start  - An Integer position in the `tokens` Array pointing to the
#             first Token of a definition.
#   :end    - An Integer position in the `tokens` Array pointing to the last
#             Token of a definition.
#   :tokens - An Array consisting of all the Token objects that make up the
#             definition.
Calculate the positions of all the specified defintion types
within the `tokens` Array.

Returns an Array of Hashes, each containing:
:start  - An Integer position in the `tokens` Array pointing to the
first Token of a definition.
:end    - An Integer position in the `tokens` Array pointing to the last
Token of a definition.
:tokens - An Array consisting of all the Token objects that make up the
definition.
Calculate the positions of all the specified defintion types within the ` tokens ` Array . Returns an Array of Hashes each containing : : start - An Integer position in the ` tokens ` Array pointing to the first Token of a definition . : end - An Integer position in the ` tokens ` Array pointing to the last Token of a definition . : tokens - An Array consisting of all the Token objects that make up the definition .
def definition_indexes(type)
      result = []
      tokens.each_with_index do |token, i|
        if token.type == type
          brace_depth = 0
          paren_depth = 0
          in_params = false
          inherited_class = nil
          tokens[i+1..-1].each_with_index do |definition_token, j|
            case definition_token.type
            when :INHERITS
              inherited_class = definition_token.next_code_token
            when :LPAREN
              in_params = true if paren_depth == 0
              paren_depth += 1
            when :RPAREN
              in_params = false if paren_depth == 1
              paren_depth -= 1
            when :LBRACE
              brace_depth += 1
            when :RBRACE
              brace_depth -= 1
              if brace_depth == 0 && !in_params
                if token.next_code_token.type != :LBRACE
                  result << {
                    :start           => i,
                    :end             => i + j + 1,
                    :tokens          => tokens[i..(i + j + 1)],
                    :param_tokens    => param_tokens(tokens[i..(i + j + 1)]),
                    :type            => type,
                    :name_token      => token.next_code_token,
                    :inherited_token => inherited_class,
                  }
                  break
                end
              end
            end
          end
        end
      end
      result
    end
def definition_indexes ( type ) result = [ ] tokens . each_with_index do | token , i | if token . type == type brace_depth = 0 paren_depth = 0 in_params = false inherited_class = nil tokens [ i + 1 .. - 1 ] . each_with_index do | definition_token , j | case definition_token . type when :INHERITS inherited_class = definition_token . next_code_token when :LPAREN in_params = true if paren_depth == 0 paren_depth += 1 when :RPAREN in_params = false if paren_depth == 1 paren_depth -= 1 when :LBRACE brace_depth += 1 when :RBRACE brace_depth -= 1 if brace_depth == 0 && ! in_params if token . next_code_token . type != :LBRACE result << { :start => i , :end => i + j + 1 , :tokens => tokens [ i .. ( i + j + 1 ) ] , :param_tokens => param_tokens ( tokens [ i .. ( i + j + 1 ) ] ) , :type => type , :name_token => token . next_code_token , :inherited_token => inherited_class , } break end end end end end end result end
Internal: Calculate the positions of all the specified defintion types
within the `tokens` Array.
Internal : Calculate the positions of all the specified defintion types within the ` tokens ` Array .
type