From 5a0e34b4f8da22e1830ec7d0a730c3686665bceb Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 8 Feb 2008 14:25:52 -0600 Subject: Refactoring the AST classes just a bit. I realized that all of the evaluate() methods only ever accepted a scope, and sometimes one other option, so I switched them all to use named arguments instead of a hash. --- lib/puppet/parser/ast/node.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'lib/puppet/parser/ast/node.rb') diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb index a296e43ba..3c5d44d1b 100644 --- a/lib/puppet/parser/ast/node.rb +++ b/lib/puppet/parser/ast/node.rb @@ -7,23 +7,15 @@ class Puppet::Parser::AST @name = :node attr_accessor :name - def evaluate(options) - scope = options[:scope] - - #pscope = if ! Puppet[:lexical] or options[:asparent] - # @scope - #else - # origscope - #end - + def evaluate(scope, resource) # We don't have to worry about the declarativeness of node parentage, # because the entry point is always a single node definition. if parent = self.parentobj - scope = parent.safeevaluate :scope => scope, :resource => options[:resource] + scope = parent.safeevaluate scope, resource end scope = scope.newscope( - :resource => options[:resource], + :resource => resource, :keyword => @keyword, :source => self, :namespace => "" # nodes are always in "" @@ -36,7 +28,7 @@ class Puppet::Parser::AST # And then evaluate our code if we have any if self.code - @code.safeevaluate(:scope => scope) + @code.safeevaluate(scope) end return scope -- cgit From fb4bdc0b02bba1291cb78ccd5c2a3198d3929d69 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 8 Feb 2008 13:54:53 -0800 Subject: More AST refactoring -- each of the code wrapping classes just returns a resource from its evaluate() method, and all of the work is done in the evaluate_code method. This makes the code cleaner, because it means 1) evaluate() has the same prototype as all of the other AST classes, 2) evaluate() is no longer called indirectly through the Parser Resource class, and 3) the classes themselves are responsible for creating the resources, rather than it being done in the Compile class. --- lib/puppet/parser/ast/node.rb | 96 +++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 49 deletions(-) (limited to 'lib/puppet/parser/ast/node.rb') diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb index 3c5d44d1b..7ff7a18e1 100644 --- a/lib/puppet/parser/ast/node.rb +++ b/lib/puppet/parser/ast/node.rb @@ -1,59 +1,57 @@ require 'puppet/parser/ast/hostclass' -class Puppet::Parser::AST - # The specific code associated with a host. Nodes are annoyingly unlike - # other objects. That's just the way it is, at least for now. - class Node < AST::HostClass - @name = :node - attr_accessor :name - - def evaluate(scope, resource) - # We don't have to worry about the declarativeness of node parentage, - # because the entry point is always a single node definition. - if parent = self.parentobj - scope = parent.safeevaluate scope, resource - end - - scope = scope.newscope( - :resource => resource, - :keyword => @keyword, - :source => self, - :namespace => "" # nodes are always in "" - ) - - # Mark our node name as a class, too, but strip it of the domain - # name. Make the mark before we evaluate the code, so that it is - # marked within the code itself. - scope.compile.class_set(self.classname, scope) - - # And then evaluate our code if we have any - if self.code - @code.safeevaluate(scope) - end - - return scope +# The specific code associated with a host. Nodes are annoyingly unlike +# other objects. That's just the way it is, at least for now. +class Puppet::Parser::AST::Node < Puppet::Parser::AST::HostClass + @name = :node + + # Evaluate the code associated with our node definition. + def evaluate_code(resource) + scope = resource.scope + + # We don't have to worry about the declarativeness of node parentage, + # because the entry point is always a single node definition. + if parent = self.parentobj + scope = parent.evaluate_code(resource) end - def initialize(options) - @parentclass = nil - super + scope = scope.newscope( + :resource => resource, + :keyword => @keyword, + :source => self, + :namespace => "" # nodes are always in "" + ) - # Do some validation on the node name - if @name =~ /[^-\w.]/ - raise Puppet::ParseError, "Invalid node name %s" % @name - end - end + # Mark our node name as a class, too, but strip it of the domain + # name. Make the mark before we evaluate the code, so that it is + # marked within the code itself. + scope.compile.class_set(self.classname, scope) - # Make sure node scopes are marked as such. - def subscope(*args) - scope = super - scope.nodescope = true - end + # And then evaluate our code if we have any + @code.safeevaluate(scope) if self.code + + return scope + end + + def initialize(options) + @parentclass = nil + super - private - # Search for the object matching our parent class. - def find_parentclass - @parser.findnode(parentclass) + # Do some validation on the node name + if @name =~ /[^-\w.]/ + raise Puppet::ParseError, "Invalid node name %s" % @name end end + + # Make sure node scopes are marked as such. + def subscope(*args) + scope = super + scope.nodescope = true + end + + private + # Search for the object matching our parent class. + def find_parentclass + @parser.findnode(parentclass) + end end -- cgit From fd0c5cbddec8dc53196a3b84e33e1000c3c0720f Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 11 Feb 2008 17:59:34 -0600 Subject: Changing the name of the Compile class to Compiler, since it's stupid to have a class named after a verb. --- lib/puppet/parser/ast/node.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/ast/node.rb') diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb index 7ff7a18e1..8cebac8a8 100644 --- a/lib/puppet/parser/ast/node.rb +++ b/lib/puppet/parser/ast/node.rb @@ -25,7 +25,7 @@ class Puppet::Parser::AST::Node < Puppet::Parser::AST::HostClass # Mark our node name as a class, too, but strip it of the domain # name. Make the mark before we evaluate the code, so that it is # marked within the code itself. - scope.compile.class_set(self.classname, scope) + scope.compiler.class_set(self.classname, scope) # And then evaluate our code if we have any @code.safeevaluate(scope) if self.code -- cgit From c8da318a2a4445e0ce10c76a7fbb64635b291ccd Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 12 Feb 2008 14:19:19 -0600 Subject: Moving the ast node tests to rspec (which I could have *sworn* I did this weekend). In the process, I fixed a couple of bugs related to differentiating between nodes and classes, and then cleaned up quite a few error messages. --- lib/puppet/parser/ast/node.rb | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) (limited to 'lib/puppet/parser/ast/node.rb') diff --git a/lib/puppet/parser/ast/node.rb b/lib/puppet/parser/ast/node.rb index 8cebac8a8..2bf6c1882 100644 --- a/lib/puppet/parser/ast/node.rb +++ b/lib/puppet/parser/ast/node.rb @@ -5,34 +5,6 @@ require 'puppet/parser/ast/hostclass' class Puppet::Parser::AST::Node < Puppet::Parser::AST::HostClass @name = :node - # Evaluate the code associated with our node definition. - def evaluate_code(resource) - scope = resource.scope - - # We don't have to worry about the declarativeness of node parentage, - # because the entry point is always a single node definition. - if parent = self.parentobj - scope = parent.evaluate_code(resource) - end - - scope = scope.newscope( - :resource => resource, - :keyword => @keyword, - :source => self, - :namespace => "" # nodes are always in "" - ) - - # Mark our node name as a class, too, but strip it of the domain - # name. Make the mark before we evaluate the code, so that it is - # marked within the code itself. - scope.compiler.class_set(self.classname, scope) - - # And then evaluate our code if we have any - @code.safeevaluate(scope) if self.code - - return scope - end - def initialize(options) @parentclass = nil super @@ -43,13 +15,19 @@ class Puppet::Parser::AST::Node < Puppet::Parser::AST::HostClass end end + def namespace + "" + end + # Make sure node scopes are marked as such. def subscope(*args) scope = super scope.nodescope = true + scope end private + # Search for the object matching our parent class. def find_parentclass @parser.findnode(parentclass) -- cgit