Class: Puppet::Parser::AST
- Includes:
- Util::Errors
- 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.
Direct Known Subclasses
Defined Under Namespace
Classes: BlockExpression, Branch, HostName, Hostclass, Leaf, Node, PopsBridge, Regex, Resource, ResourceInstance, ResourceParam, TopLevelConstruct
Constant Summary collapse
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
-
#evaluate(scope) ⇒ Object
Evaluate the current object.
-
#initialize(file: nil, line: nil, pos: nil) ⇒ AST
constructor
A new instance of AST.
- #inspect ⇒ Object
-
#safeevaluate(scope) ⇒ Object
The version of the evaluate method that should be called, because it correctly handles errors.
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, error_location, error_location_with_space, error_location_with_unknowns, #exceptwrap, #fail
Constructor Details
#initialize(file: nil, line: nil, pos: nil) ⇒ AST
Returns a new instance of AST.
47 48 49 50 51 |
# File 'lib/puppet/parser/ast.rb', line 47 def initialize(file: nil, line: nil, pos: nil) @file = file @line = line @pos = pos end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
13 14 15 |
# File 'lib/puppet/parser/ast.rb', line 13 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
13 14 15 |
# File 'lib/puppet/parser/ast.rb', line 13 def line @line end |
#parent ⇒ Object
Returns the value of attribute parent.
13 14 15 |
# File 'lib/puppet/parser/ast.rb', line 13 def parent @parent end |
#pos ⇒ Object
Returns the value of attribute pos.
13 14 15 |
# File 'lib/puppet/parser/ast.rb', line 13 def pos @pos end |
#scope ⇒ Object
Returns the value of attribute scope.
13 14 15 |
# File 'lib/puppet/parser/ast.rb', line 13 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.
21 22 |
# File 'lib/puppet/parser/ast.rb', line 21 def evaluate(scope) end |
#inspect ⇒ Object
15 16 17 |
# File 'lib/puppet/parser/ast.rb', line 15 def inspect "( #{self.class} #{self} #{@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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet/parser/ast.rb', line 28 def safeevaluate(scope) # We duplicate code here, rather than using exceptwrap, because this # is called so many times during parsing. evaluate(scope) rescue Puppet::Pops::Evaluator::PuppetStopIteration => detail raise detail # # Only deals with StopIteration from the break() function as a general # # StopIteration is a general runtime problem # raise Puppet::ParseError.new(detail.message, detail.file, detail.line, detail) 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 |