# class Puppet::Parser::AST

The base class for all of the objects that make up the parse trees. Handles things like file name, line #, and also does the initialization for all of the parameters of all of the child objects.

An object that collects stored objects from the central cache and returns them to the current host, yo.

An object that collects stored objects from the central cache and returns them to the current host, yo.

An object that returns a boolean which is the boolean not of the given value.

An object that returns a boolean which is the boolean not of the given value.

Any normal puppet resource declaration. Can point to a definition or a builtin type.

### Constants

AST

  The base class for all of the objects that make up the parse trees. Handles things like file name, line #, and also does the initialization for all of the parameters of all of the child objects.

### Attributes

use_docs[RW]
file[RW]
line[RW]
parent[RW]
scope[RW]

### Public Class Methods

new(args) click to toggle source

Initialize the object. Requires a hash as the argument, and takes each of the parameters of the hash and calls the settor method for them. This is probably pretty inefficient and should likely be changed at some point.

    # File lib/puppet/parser/ast.rb, line 77
    def initialize(args)
      set_options(args)
    end

### Public Instance Methods

associates_doc() click to toggle source

    # File lib/puppet/parser/ast.rb, line 31
    def associates_doc
      self.use_docs = true
    end

evaluate(*options) click to toggle source

Evaluate the current object. Just a stub method, since the subclass should override this method.

    # File lib/puppet/parser/ast.rb, line 38
    def evaluate(*options)
      raise Puppet::DevError, "Did not override #evaluate in #{self.class}"
    end

evaluate_match(value, scope) click to toggle source

evaluate ourselves, and match

    # File lib/puppet/parser/ast.rb, line 82
    def evaluate_match(value, scope)
      obj = self.safeevaluate(scope)

      obj   = obj.downcase   if obj.respond_to?(:downcase)
      value = value.downcase if value.respond_to?(:downcase)

      obj   = Puppet::Parser::Scope.number?(obj)   || obj
      value = Puppet::Parser::Scope.number?(value) || value

      # "" == undef for case/selector/if
      obj == value or (obj == "" and value == :undef) or (obj == :undef and value == "")
    end

inspect() click to toggle source

    # File lib/puppet/parser/ast.rb, line 19
    def inspect
      "( #{self.class} #{self.to_s} #{@children.inspect} )"
    end

parsefail(message) click to toggle source

Throw a parse error.

    # File lib/puppet/parser/ast.rb, line 43
    def parsefail(message)
      self.fail(Puppet::ParseError, message)
    end

parsewrap() { || ... } click to toggle source

Wrap a statemp in a reusable way so we always throw a parse error.

    # File lib/puppet/parser/ast.rb, line 48
    def parsewrap
      exceptwrap :type => Puppet::ParseError do
        yield
      end
    end

safeevaluate(*options) click to toggle source

The version of the evaluate method that should be called, because it correctly handles errors. It is critical to use this method because it can enable you to catch the error where it happens, rather than much higher up the stack.

    # File lib/puppet/parser/ast.rb, line 58
    def safeevaluate(*options)
      # We duplicate code here, rather than using exceptwrap, because this
      # is called so many times during parsing.
      begin
        return self.evaluate(*options)
      rescue Puppet::Error => detail
        raise adderrorcontext(detail)
      rescue => detail
        error = Puppet::ParseError.new(detail.to_s, nil, nil, detail)
        # We can't use self.fail here because it always expects strings,
        # not exceptions.
        raise adderrorcontext(error, detail)
      end
    end

use_docs() click to toggle source

don’t fetch lexer comment by default

    # File lib/puppet/parser/ast.rb, line 24
    def use_docs
      self.class.use_docs
    end