Class: Puppet::Parser::AST

Inherits:
Object show all
Includes:
Util::Errors, Util::MethodHelper
Defined in:
lib/puppet/parser/ast.rb

Overview

The base class for the 3x “parse tree”, now only used by the top level constructs and the compiler. Handles things like file name, line #, and also does the initialization for all of the parameters of all of the child objects.

API:

  • public

Direct Known Subclasses

Branch, Leaf, TopLevelConstruct

Defined Under Namespace

Classes: BlockExpression, Branch, HostName, Hostclass, Leaf, Node, PopsBridge, Regex, Resource, ResourceInstance, ResourceParam, TopLevelConstruct

Constant Summary collapse

AST =

API:

  • public

Puppet::Parser::AST

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Methods included from Util::Errors

#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail

Constructor Details

#initialize(args) ⇒ AST

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

API:

  • public



46
47
48
# File 'lib/puppet/parser/ast.rb', line 46

def initialize(args)
  set_options(args)
end

Instance Attribute Details

#fileObject

API:

  • public



12
13
14
# File 'lib/puppet/parser/ast.rb', line 12

def file
  @file
end

#lineObject

API:

  • public



12
13
14
# File 'lib/puppet/parser/ast.rb', line 12

def line
  @line
end

#parentObject

API:

  • public



12
13
14
# File 'lib/puppet/parser/ast.rb', line 12

def parent
  @parent
end

#posObject

API:

  • public



12
13
14
# File 'lib/puppet/parser/ast.rb', line 12

def pos
  @pos
end

#scopeObject

API:

  • public



12
13
14
# File 'lib/puppet/parser/ast.rb', line 12

def scope
  @scope
end

Instance Method Details

#evaluate(scope) ⇒ Object

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

API:

  • public



20
21
# File 'lib/puppet/parser/ast.rb', line 20

def evaluate(scope)
end

#inspectObject

API:

  • public



14
15
16
# File 'lib/puppet/parser/ast.rb', line 14

def inspect
  "( #{self.class} #{self.to_s} #{@children.inspect} )"
end

#safeevaluate(scope) ⇒ Object

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.

API:

  • public



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/puppet/parser/ast.rb', line 27

def safeevaluate(scope)
  # We duplicate code here, rather than using exceptwrap, because this
  # is called so many times during parsing.
  begin
    return self.evaluate(scope)
  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