# class Puppet::Parser::Parser

### Constants

AST

  #<RDoc::Comment:0x9814fbc>

  #<RDoc::Comment:0x9c02048>

  #<RDoc::Comment:0x9828af8>

  #<RDoc::Comment:0x97d9b10>

  #<RDoc::Comment:0x9c18104>

  #<RDoc::Comment:0x99a4b48>

  #<RDoc::Comment:0x90a88dc>

  #<RDoc::Comment:0x891933c>

  #<RDoc::Comment:0x95788bc>

  #<RDoc::Comment:0x8fba2cc>

  #<RDoc::Comment:0xa00d3b8>

  #<RDoc::Comment:0xac4a874>

  #<RDoc::Comment:0xaca1138>

  #<RDoc::Comment:0xae6a758>

  #<RDoc::Comment:0xaf161d4>

  #<RDoc::Comment:0xafaa6a4>

  #<RDoc::Comment:0xaad6ce0>

  #<RDoc::Comment:0x9354374>

  #<RDoc::Comment:0x99c1860>

  #<RDoc::Comment:0x9ac818c>

  #<RDoc::Comment:0xb7817d8>

  #<RDoc::Comment:0x9810890>

  #<RDoc::Comment:0x8f104ac>

  #<RDoc::Comment:0x9971144>

  #<RDoc::Comment:0x9ae78e8>

  #<RDoc::Comment:0x9b375c8>

  #<RDoc::Comment:0x9899398>

  #<RDoc::Comment:0x9bbea3c>

Racc_arg
Racc_debug_parser
Racc_token_to_s_table

### Attributes

environment[R]
files[RW]
lexer[RW]
version[R]

### Public Class Methods

new(env) click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 99
    def initialize(env)
      # The environment is needed to know how to find the resource type collection.
      @environment = env.is_a?(String) ? Puppet::Node::Environment.new(env) : env
      initvars
    end

### Public Instance Methods

_reduce_none(val, _values, result) click to toggle source

    # File lib/puppet/parser/parser.rb, line 2504
    def _reduce_none(val, _values, result)
      val[0]
    end

addcontext(message, obj = nil) click to toggle source

Add context to a message; useful for error messages and such.

    # File lib/puppet/parser/parser_support.rb, line 25
    def addcontext(message, obj = nil)
      obj ||= @lexer

      message += " on line #{obj.line}"
      if file = obj.file
        message += " in file #{file}"
      end

      message
    end

aryfy(arg) click to toggle source

Create an AST array containing a single element

    # File lib/puppet/parser/parser_support.rb, line 37
    def aryfy(arg)
      ast AST::ASTArray, :children => [arg]
    end

ast(klass, hash = {}) click to toggle source

Create an AST object, and automatically add the file and line information if available.

    # File lib/puppet/parser/parser_support.rb, line 43
    def ast(klass, hash = {})
      klass.new ast_context(klass.use_docs, hash[:line]).merge(hash)
    end

ast_context(include_docs = false, ast_line = nil) click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 47
    def ast_context(include_docs = false, ast_line = nil)
      result = {
        :line => ast_line || lexer.line,
        :file => lexer.file
      }
      result[:doc] = lexer.getcomment(result[:line]) if include_docs
      result
    end

classname(name) click to toggle source

The fully qualifed name, with the full namespace.

    # File lib/puppet/parser/parser_support.rb, line 57
    def classname(name)
      [@lexer.namespace, name].join("::").sub(/^::/, '')
    end

clear() click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 61
    def clear
      initvars
    end

error(message, options = {}) click to toggle source

Raise a Parse error.

    # File lib/puppet/parser/parser_support.rb, line 66
    def error(message, options = {})
      if brace = @lexer.expected
        message += "; expected '%s'"
      end
      except = Puppet::ParseError.new(message)
      except.line = options[:line] || @lexer.line
      except.file = options[:file] || @lexer.file

      raise except
    end

file=(file) click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 79
    def file=(file)
      unless FileTest.exist?(file)
        unless file =~ /\.pp$/
          file = file + ".pp"
        end
      end
      raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file)

      watch_file(file)
      @lexer.file = file
    end

import(file) click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 95
    def import(file)
      known_resource_types.loader.import(file, @lexer.file)
    end

initvars() click to toggle source

Initialize or reset all of our variables.

    # File lib/puppet/parser/parser_support.rb, line 106
    def initvars
      @lexer = Puppet::Parser::Lexer.new
    end

namesplit(fullname) click to toggle source

Split an fq name into a namespace and name

    # File lib/puppet/parser/parser_support.rb, line 111
    def namesplit(fullname)
      ary = fullname.split("::")
      n = ary.pop || ""
      ns = ary.join("::")
      return ns, n
    end

on_error(token,value,stack) click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 118
    def on_error(token,value,stack)
      if token == 0 # denotes end of file
        value = 'end of file'
      else
        value = "'#{value[:value]}'"
      end
      error = "Syntax error at #{value}"

      if brace = @lexer.expected
        error += "; expected '#{brace}'"
      end

      except = Puppet::ParseError.new(error)
      except.line = @lexer.line
      except.file = @lexer.file if @lexer.file

      raise except
    end

parse(string = nil) click to toggle source

how should I do error handling here?

    # File lib/puppet/parser/parser_support.rb, line 138
    def parse(string = nil)
      if self.file =~ /\.rb$/
        main = parse_ruby_file
      else
        self.string = string if string
        begin
          @yydebug = false
          main = yyparse(@lexer,:scan)
        rescue Puppet::ParseError => except
          except.line ||= @lexer.line
          except.file ||= @lexer.file
          raise except
        rescue => except
          raise Puppet::ParseError.new(except.message, @lexer.file, @lexer.line, except)
        end
      end
      # Store the results as the top-level class.
      return Puppet::Parser::AST::Hostclass.new('', :code => main)
    ensure
      @lexer.clear
    end

parse_ruby_file() click to toggle source

    # File lib/puppet/parser/parser_support.rb, line 160
    def parse_ruby_file
      Puppet.deprecation_warning("Use of the Ruby DSL is deprecated.")

      # Execute the contents of the file inside its own "main" object so
      # that it can call methods in the resource type API.
      main_object = Puppet::DSL::ResourceTypeAPI.new
      main_object.instance_eval(File.read(self.file))

      # Then extract any types that were created.
      Puppet::Parser::AST::ASTArray.new :children => main_object.instance_eval { @__created_ast_objects__ }
    end