diff options
| author | Luke Kanies <luke@madstop.com> | 2008-10-17 09:01:04 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-10-17 09:01:04 -0500 |
| commit | 8aee40de69e6fe8d67ab58a2e223443b15820584 (patch) | |
| tree | 89e230df3b43302a542f2cb6869f63e2fb93f6d8 /lib/puppet/parser/ast | |
| parent | 1b517d2fb048603bd1743a662bde74e8ae4b13dc (diff) | |
| parent | a74ec60d33dee1c592ec858faeccc23d7a7b79f3 (diff) | |
| download | puppet-8aee40de69e6fe8d67ab58a2e223443b15820584.tar.gz puppet-8aee40de69e6fe8d67ab58a2e223443b15820584.tar.xz puppet-8aee40de69e6fe8d67ab58a2e223443b15820584.zip | |
Merge branch '0.24.x' Removed the 'after' blocks that call Type.clear,
since that method is deprecated.
Conflicts:
CHANGELOG
bin/puppetca
lib/puppet/file_serving/fileset.rb
lib/puppet/network/xmlrpc/client.rb
lib/puppet/type/file/selcontext.rb
spec/unit/file_serving/metadata.rb
spec/unit/type/file.rb
Diffstat (limited to 'lib/puppet/parser/ast')
| -rw-r--r-- | lib/puppet/parser/ast/arithmetic_operator.rb | 41 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/boolean_operator.rb | 48 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/collexpr.rb | 7 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/comparison_operator.rb | 37 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/minus.rb | 23 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/nop.rb | 11 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/not.rb | 19 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/resource_override.rb | 39 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/resource_reference.rb | 16 |
9 files changed, 218 insertions, 23 deletions
diff --git a/lib/puppet/parser/ast/arithmetic_operator.rb b/lib/puppet/parser/ast/arithmetic_operator.rb new file mode 100644 index 000000000..8d9cef86a --- /dev/null +++ b/lib/puppet/parser/ast/arithmetic_operator.rb @@ -0,0 +1,41 @@ +require 'puppet' +require 'puppet/parser/ast/branch' + +class Puppet::Parser::AST + class ArithmeticOperator < AST::Branch + + attr_accessor :operator, :lval, :rval + + # Iterate across all of our children. + def each + [@lval,@rval,@operator].each { |child| yield child } + end + + # Returns a boolean which is the result of the boolean operation + # of lval and rval operands + def evaluate(scope) + # evaluate the operands, should return a boolean value + lval = @lval.safeevaluate(scope) + lval = Puppet::Parser::Scope.number?(lval) + if lval == nil + raise ArgumentError, "left operand of %s is not a number" % @operator + end + rval = @rval.safeevaluate(scope) + rval = Puppet::Parser::Scope.number?(rval) + if rval == nil + raise ArgumentError, "right operand of %s is not a number" % @operator + end + + # compute result + lval.send(@operator, rval) + end + + def initialize(hash) + super + + unless %w{+ - * / << >>}.include?(@operator) + raise ArgumentError, "Invalid arithmetic operator %s" % @operator + end + end + end +end diff --git a/lib/puppet/parser/ast/boolean_operator.rb b/lib/puppet/parser/ast/boolean_operator.rb new file mode 100644 index 000000000..c3b5c7d41 --- /dev/null +++ b/lib/puppet/parser/ast/boolean_operator.rb @@ -0,0 +1,48 @@ +require 'puppet' +require 'puppet/parser/ast/branch' + +class Puppet::Parser::AST + class BooleanOperator < AST::Branch + + attr_accessor :operator, :lval, :rval + + # Iterate across all of our children. + def each + [@lval,@rval,@operator].each { |child| yield child } + end + + # Returns a boolean which is the result of the boolean operation + # of lval and rval operands + def evaluate(scope) + # evaluate the first operand, should return a boolean value + lval = @lval.safeevaluate(scope) + + # return result + # lazy evaluate right operand + case @operator + when "and"; + if Puppet::Parser::Scope.true?(lval) + rval = @rval.safeevaluate(scope) + Puppet::Parser::Scope.true?(rval) + else # false and false == false + false + end + when "or"; + if Puppet::Parser::Scope.true?(lval) + true + else + rval = @rval.safeevaluate(scope) + Puppet::Parser::Scope.true?(rval) + end + end + end + + def initialize(hash) + super + + unless %w{and or}.include?(@operator) + raise ArgumentError, "Invalid boolean operator %s" % @operator + end + end + end +end diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb index 3e13d9400..baed325cb 100644 --- a/lib/puppet/parser/ast/collexpr.rb +++ b/lib/puppet/parser/ast/collexpr.rb @@ -30,7 +30,12 @@ class CollExpr < AST::Branch case @oper when "and": code1.call(resource) and code2.call(resource) when "or": code1.call(resource) or code2.call(resource) - when "==": resource[str1] == str2 + when "==": + if resource[str1].is_a?(Array) && form != :exported + resource[str1].include?(str2) + else + resource[str1] == str2 + end when "!=": resource[str1] != str2 end end diff --git a/lib/puppet/parser/ast/comparison_operator.rb b/lib/puppet/parser/ast/comparison_operator.rb new file mode 100644 index 000000000..63aa36c7f --- /dev/null +++ b/lib/puppet/parser/ast/comparison_operator.rb @@ -0,0 +1,37 @@ +require 'puppet' +require 'puppet/parser/ast/branch' + +class Puppet::Parser::AST + class ComparisonOperator < AST::Branch + + attr_accessor :operator, :lval, :rval + + # Iterate across all of our children. + def each + [@lval,@rval,@operator].each { |child| yield child } + end + + # Returns a boolean which is the result of the boolean operation + # of lval and rval operands + def evaluate(scope) + # evaluate the operands, should return a boolean value + lval = @lval.safeevaluate(scope) + rval = @rval.safeevaluate(scope) + + # return result + unless @operator == '!=' + lval.send(@operator,rval) + else + lval != rval + end + end + + def initialize(hash) + super + + unless %w{== != < > <= >=}.include?(@operator) + raise ArgumentError, "Invalid comparison operator %s" % @operator + end + end + end +end diff --git a/lib/puppet/parser/ast/minus.rb b/lib/puppet/parser/ast/minus.rb new file mode 100644 index 000000000..b0779a8ee --- /dev/null +++ b/lib/puppet/parser/ast/minus.rb @@ -0,0 +1,23 @@ +require 'puppet' +require 'puppet/parser/ast/branch' + +# An object that returns a boolean which is the boolean not +# of the given value. +class Puppet::Parser::AST + class Minus < AST::Branch + attr_accessor :value + + def each + yield @value + end + + def evaluate(scope) + val = @value.safeevaluate(scope) + val = Puppet::Parser::Scope.number?(val) + if val == nil + raise ArgumentError, "minus operand %s is not a number" % val + end + return -val + end + end +end diff --git a/lib/puppet/parser/ast/nop.rb b/lib/puppet/parser/ast/nop.rb new file mode 100644 index 000000000..ea5232043 --- /dev/null +++ b/lib/puppet/parser/ast/nop.rb @@ -0,0 +1,11 @@ +require 'puppet/parser/ast/branch' + +class Puppet::Parser::AST + # This class is a no-op, it doesn't produce anything + # when evaluated, hence it's name :-) + class Nop < AST::Leaf + def evaluate(scope) + # nothing to do + end + end +end diff --git a/lib/puppet/parser/ast/not.rb b/lib/puppet/parser/ast/not.rb new file mode 100644 index 000000000..c8fa1df2c --- /dev/null +++ b/lib/puppet/parser/ast/not.rb @@ -0,0 +1,19 @@ +require 'puppet' +require 'puppet/parser/ast/branch' + +# An object that returns a boolean which is the boolean not +# of the given value. +class Puppet::Parser::AST + class Not < AST::Branch + attr_accessor :value + + def each + yield @value + end + + def evaluate(scope) + val = @value.safeevaluate(scope) + return ! Puppet::Parser::Scope.true?(val) + end + end +end diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index f9464acda..8380dcd00 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -19,7 +19,7 @@ class Puppet::Parser::AST # in the current scope. def evaluate(scope) # Get our object reference. - object = @object.safeevaluate(scope) + resource = @object.safeevaluate(scope) hash = {} @@ -30,21 +30,28 @@ class Puppet::Parser::AST # Now we just create a normal resource, but we call a very different # method on the scope. - obj = Puppet::Parser::Resource.new( - :type => object.type, - :title => object.title, - :params => params, - :file => @file, - :line => @line, - :source => scope.source, - :scope => scope - ) - - # Now we tell the scope that it's an override, and it behaves as - # necessary. - scope.compiler.add_override(obj) - - obj + resource = [resource] unless resource.is_a?(Array) + + resource = resource.collect do |r| + res = Puppet::Parser::Resource.new( + :type => r.type, + :title => r.title, + :params => params, + :file => @file, + :line => @line, + :source => scope.source, + :scope => scope + ) + + # Now we tell the scope that it's an override, and it behaves as + # necessary. + scope.compiler.add_override(res) + + res + end + # decapsulate array in case of only one item + return resource.pop if resource.length == 1 + return resource end # Create our ResourceDef. Handles type checking for us. diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb index 4bb41165a..e5e2dce99 100644 --- a/lib/puppet/parser/ast/resource_reference.rb +++ b/lib/puppet/parser/ast/resource_reference.rb @@ -24,16 +24,20 @@ class Puppet::Parser::AST # and name. def evaluate(scope) title = @title.safeevaluate(scope) + title = [title] unless title.is_a?(Array) + if @type.to_s.downcase == "class" - objtype = "class" - title = qualified_class(scope, title) + resource_type = "class" + title = title.collect { |t| qualified_class(scope, t) } else - objtype = qualified_type(scope) + resource_type = qualified_type(scope) end - return Puppet::Parser::Resource::Reference.new( - :type => objtype, :title => title - ) + title = title.collect { |t| Puppet::Parser::Resource::Reference.new( + :type => resource_type, :title => t + ) } + return title.pop if title.length == 1 + return title end # Look up a fully qualified class name. |
