diff --git a/lib/puppet/parser/ast/block_expression.rb b/lib/puppet/parser/ast/block_expression.rb index b6b7e66b4..386b6ad55 100644 --- a/lib/puppet/parser/ast/block_expression.rb +++ b/lib/puppet/parser/ast/block_expression.rb @@ -1,40 +1,29 @@ require 'puppet/parser/ast/branch' class Puppet::Parser::AST class BlockExpression < Branch include Enumerable # Evaluate contained expressions, produce result of the last def evaluate(scope) result = nil @children.each do |child| result = child.safeevaluate(scope) end result end # Return a child by index. def [](index) @children[index] end - def push(*ary) - ary.each { |child| - #Puppet.debug "adding %s(%s) of type %s to %s" % - # [child, child.object_id, child.class.to_s.sub(/.+::/,''), - # self.object_id] - @children.push(child) - } - - self - end - def sequence_with(other) Puppet::Parser::AST::BlockExpression.new(:children => self.children + other.children) end def to_s "[" + @children.collect { |c| c.to_s }.join(', ') + "]" end end end diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index fde91f006..2a88e8d3f 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -1,76 +1,75 @@ class Puppet::Parser::AST # The base class for all of the leaves of the parse trees. These # basically just have types and values. Both of these parameters # are simple values, not AST objects. class Leaf < AST attr_accessor :value, :type # Return our value. def evaluate(scope) @value end def match(value) @value == value end def to_s @value.to_s unless @value.nil? end end - # Host names, either fully qualified or just the short name, or even a regex class HostName < AST::Leaf def initialize(hash) super # Note that this is an AST::Regex, not a Regexp unless @value.is_a?(Regex) @value = @value.to_s.downcase if @value =~ /[^-\w.]/ raise Puppet::DevError, "'#{@value}' is not a valid hostname" end end end # implementing eql? and hash so that when an HostName is stored # in a hash it has the same hashing properties as the underlying value def eql?(value) @value.eql?(value.is_a?(HostName) ? value.value : value) end def hash @value.hash end end class Regex < AST::Leaf def initialize(hash) super # transform value from hash options unless it is already a regular expression @value = Regexp.new(@value) unless @value.is_a?(Regexp) end # we're returning self here to wrap the regexp and to be used in places # where a string would have been used, without modifying any client code. # For instance, in many places we have the following code snippet: # val = @val.safeevaluate(@scope) # if val.match(otherval) # ... # end # this way, we don't have to modify this test specifically for handling # regexes. def evaluate(scope) self end def match(value) @value.match(value) end def to_s "/#{@value.source}/" end end end