Class: Puppet::Parser::AST

Inherits:
Object show all
Includes:
Util::Docs, Util::Errors, Util::MethodHelper
Defined in:
lib/puppet/parser/ast.rb,
lib/puppet/parser/ast/nop.rb,
lib/puppet/parser/ast/not.rb,
lib/puppet/parser/ast/else.rb,
lib/puppet/parser/ast/leaf.rb,
lib/puppet/parser/ast/minus.rb,
lib/puppet/parser/ast/branch.rb,
lib/puppet/parser/ast/lambda.rb,
lib/puppet/parser/ast/vardef.rb,
lib/puppet/parser/ast/asthash.rb,
lib/puppet/parser/ast/caseopt.rb,
lib/puppet/parser/ast/astarray.rb,
lib/puppet/parser/ast/collexpr.rb,
lib/puppet/parser/ast/function.rb,
lib/puppet/parser/ast/resource.rb,
lib/puppet/parser/ast/selector.rb,
lib/puppet/parser/ast/collection.rb,
lib/puppet/parser/ast/ifstatement.rb,
lib/puppet/parser/ast/in_operator.rb,
lib/puppet/parser/ast/method_call.rb,
lib/puppet/parser/ast/casestatement.rb,
lib/puppet/parser/ast/resourceparam.rb,
lib/puppet/parser/ast/match_operator.rb,
lib/puppet/parser/ast/block_expression.rb,
lib/puppet/parser/ast/boolean_operator.rb,
lib/puppet/parser/ast/resource_defaults.rb,
lib/puppet/parser/ast/resource_instance.rb,
lib/puppet/parser/ast/resource_override.rb,
lib/puppet/parser/ast/arithmetic_operator.rb,
lib/puppet/parser/ast/comparison_operator.rb

Overview

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

Direct Known Subclasses

TopLevelConstruct

Defined Under Namespace

Classes: ASTArray, ASTHash, ArithmeticOperator, ArithmeticOperator2, BlockExpression, Boolean, BooleanOperator, Branch, CaseOpt, CaseStatement, ClassName, CollExpr, Collection, ComparisonOperator, Concat, Default, Definition, Else, FlatString, Function, HashOrArrayAccess, HostName, Hostclass, IfStatement, InOperator, Lambda, Leaf, MatchOperator, MethodCall, Minus, Name, Node, Nop, Not, PopsBridge, Regex, Relationship, Resource, ResourceDefaults, ResourceInstance, ResourceOverride, ResourceParam, ResourceReference, Selector, String, TopLevelConstruct, Type, Undef, VarDef, Variable

Constant Summary collapse

AST =

Do this so I don’t have to type the full path in all of the subclasses

Puppet::Parser::AST

Constants included from Util::Docs

Util::Docs::HEADER_LEVELS

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from Util::Docs

#doc, #nodoc

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Docs

#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub

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 settor method for them. This is probably pretty inefficient and should likely be changed at some point.



76
77
78
# File 'lib/puppet/parser/ast.rb', line 76

def initialize(args)
  set_options(args)
end

Class Attribute Details

.use_docsObject



30
31
32
# File 'lib/puppet/parser/ast.rb', line 30

def use_docs
  @use_docs
end

Instance Attribute Details

#fileObject



17
18
19
# File 'lib/puppet/parser/ast.rb', line 17

def file
  @file
end

#lineObject



17
18
19
# File 'lib/puppet/parser/ast.rb', line 17

def line
  @line
end

#parentObject



17
18
19
# File 'lib/puppet/parser/ast.rb', line 17

def parent
  @parent
end

#posObject



17
18
19
# File 'lib/puppet/parser/ast.rb', line 17

def pos
  @pos
end

#scopeObject



17
18
19
# File 'lib/puppet/parser/ast.rb', line 17

def scope
  @scope
end

Class Method Details

.associates_docObject



31
32
33
# File 'lib/puppet/parser/ast.rb', line 31

def associates_doc
  self.use_docs = true
end

Instance Method Details

#evaluate(*options) ⇒ Object

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



38
39
# File 'lib/puppet/parser/ast.rb', line 38

def evaluate(*options)
end

#evaluate_match(value, scope) ⇒ Object

evaluate ourselves, and match



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/puppet/parser/ast.rb', line 81

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

#inspectObject



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

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

#parsefail(message) ⇒ Object

Throw a parse error.



42
43
44
# File 'lib/puppet/parser/ast.rb', line 42

def parsefail(message)
  self.fail(Puppet::ParseError, message)
end

#parsewrapObject

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



47
48
49
50
51
# File 'lib/puppet/parser/ast.rb', line 47

def parsewrap
  exceptwrap :type => Puppet::ParseError do
    yield
  end
end

#safeevaluate(*options) ⇒ 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.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/puppet/parser/ast.rb', line 57

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_docsObject

don’t fetch lexer comment by default



24
25
26
# File 'lib/puppet/parser/ast.rb', line 24

def use_docs
  self.class.use_docs
end