summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/parser/ast
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/arithmetic_operator.rb54
-rw-r--r--lib/puppet/parser/ast/astarray.rb100
-rw-r--r--lib/puppet/parser/ast/asthash.rb52
-rw-r--r--lib/puppet/parser/ast/boolean_operator.rb66
-rw-r--r--lib/puppet/parser/ast/branch.rb58
-rw-r--r--lib/puppet/parser/ast/caseopt.rb100
-rw-r--r--lib/puppet/parser/ast/casestatement.rb60
-rw-r--r--lib/puppet/parser/ast/collection.rb78
-rw-r--r--lib/puppet/parser/ast/collexpr.rb132
-rw-r--r--lib/puppet/parser/ast/comparison_operator.rb66
-rw-r--r--lib/puppet/parser/ast/else.rb26
-rw-r--r--lib/puppet/parser/ast/function.rb68
-rw-r--r--lib/puppet/parser/ast/ifstatement.rb46
-rw-r--r--lib/puppet/parser/ast/in_operator.rb28
-rw-r--r--lib/puppet/parser/ast/leaf.rb342
-rw-r--r--lib/puppet/parser/ast/match_operator.rb32
-rw-r--r--lib/puppet/parser/ast/minus.rb26
-rw-r--r--lib/puppet/parser/ast/nop.rb12
-rw-r--r--lib/puppet/parser/ast/not.rb18
-rw-r--r--lib/puppet/parser/ast/relationship.rb84
-rw-r--r--lib/puppet/parser/ast/resource.rb108
-rw-r--r--lib/puppet/parser/ast/resource_defaults.rb32
-rw-r--r--lib/puppet/parser/ast/resource_override.rb98
-rw-r--r--lib/puppet/parser/ast/resource_reference.rb26
-rw-r--r--lib/puppet/parser/ast/resourceparam.rb36
-rw-r--r--lib/puppet/parser/ast/selector.rb60
-rw-r--r--lib/puppet/parser/ast/tag.rb32
-rw-r--r--lib/puppet/parser/ast/vardef.rb40
28 files changed, 940 insertions, 940 deletions
diff --git a/lib/puppet/parser/ast/arithmetic_operator.rb b/lib/puppet/parser/ast/arithmetic_operator.rb
index 6b9a6018c..33352d727 100644
--- a/lib/puppet/parser/ast/arithmetic_operator.rb
+++ b/lib/puppet/parser/ast/arithmetic_operator.rb
@@ -2,38 +2,38 @@ require 'puppet'
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- class ArithmeticOperator < AST::Branch
+ class ArithmeticOperator < AST::Branch
- attr_accessor :operator, :lval, :rval
+ attr_accessor :operator, :lval, :rval
- # Iterate across all of our children.
- def each
- [@lval,@rval,@operator].each { |child| yield child }
- end
+ # 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 #{@operator} is not a number"
- end
- rval = @rval.safeevaluate(scope)
- rval = Puppet::Parser::Scope.number?(rval)
- if rval == nil
- raise ArgumentError, "right operand of #{@operator} is not a number"
- 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 #{@operator} is not a number"
+ end
+ rval = @rval.safeevaluate(scope)
+ rval = Puppet::Parser::Scope.number?(rval)
+ if rval == nil
+ raise ArgumentError, "right operand of #{@operator} is not a number"
+ end
- # compute result
- lval.send(@operator, rval)
- end
+ # compute result
+ lval.send(@operator, rval)
+ end
- def initialize(hash)
- super
+ def initialize(hash)
+ super
- raise ArgumentError, "Invalid arithmetic operator #{@operator}" unless %w{+ - * / << >>}.include?(@operator)
- end
+ raise ArgumentError, "Invalid arithmetic operator #{@operator}" unless %w{+ - * / << >>}.include?(@operator)
end
+ end
end
diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb
index f0a0c5602..529998e3c 100644
--- a/lib/puppet/parser/ast/astarray.rb
+++ b/lib/puppet/parser/ast/astarray.rb
@@ -1,61 +1,61 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # The basic container class. This object behaves almost identically
- # to a normal array except at initialization time. Note that its name
- # is 'AST::ASTArray', rather than plain 'AST::Array'; I had too many
- # bugs when it was just 'AST::Array', because things like
- # 'object.is_a?(Array)' never behaved as I expected.
- class ASTArray < Branch
- include Enumerable
-
- # Return a child by index. Probably never used.
- def [](index)
- @children[index]
- end
+ # The basic container class. This object behaves almost identically
+ # to a normal array except at initialization time. Note that its name
+ # is 'AST::ASTArray', rather than plain 'AST::Array'; I had too many
+ # bugs when it was just 'AST::Array', because things like
+ # 'object.is_a?(Array)' never behaved as I expected.
+ class ASTArray < Branch
+ include Enumerable
+
+ # Return a child by index. Probably never used.
+ def [](index)
+ @children[index]
+ end
- # Evaluate our children.
- def evaluate(scope)
- # Make a new array, so we don't have to deal with the details of
- # flattening and such
- items = []
-
- # First clean out any AST::ASTArrays
- @children.each { |child|
- if child.instance_of?(AST::ASTArray)
- child.each do |ac|
- items << ac
- end
- else
- items << child
- end
- }
-
- rets = items.flatten.collect { |child|
- child.safeevaluate(scope)
- }
- rets.reject { |o| o.nil? }
+ # Evaluate our children.
+ def evaluate(scope)
+ # Make a new array, so we don't have to deal with the details of
+ # flattening and such
+ items = []
+
+ # First clean out any AST::ASTArrays
+ @children.each { |child|
+ if child.instance_of?(AST::ASTArray)
+ child.each do |ac|
+ items << ac
+ end
+ else
+ items << child
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)
- }
+ rets = items.flatten.collect { |child|
+ child.safeevaluate(scope)
+ }
+ rets.reject { |o| o.nil? }
+ end
- self
- 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)
+ }
- def to_s
- "[" + @children.collect { |c| c.to_s }.join(', ') + "]"
- end
+ self
+ end
+
+ def to_s
+ "[" + @children.collect { |c| c.to_s }.join(', ') + "]"
end
+ end
- # A simple container class, containing the parameters for an object.
- # Used for abstracting the grammar declarations. Basically unnecessary
- # except that I kept finding bugs because I had too many arrays that
- # meant completely different things.
- class ResourceInstance < ASTArray; end
+ # A simple container class, containing the parameters for an object.
+ # Used for abstracting the grammar declarations. Basically unnecessary
+ # except that I kept finding bugs because I had too many arrays that
+ # meant completely different things.
+ class ResourceInstance < ASTArray; end
end
diff --git a/lib/puppet/parser/ast/asthash.rb b/lib/puppet/parser/ast/asthash.rb
index d16b7459f..ae81d35dd 100644
--- a/lib/puppet/parser/ast/asthash.rb
+++ b/lib/puppet/parser/ast/asthash.rb
@@ -1,37 +1,37 @@
require 'puppet/parser/ast/leaf'
class Puppet::Parser::AST
- class ASTHash < Leaf
- include Enumerable
+ class ASTHash < Leaf
+ include Enumerable
- # Evaluate our children.
- def evaluate(scope)
- items = {}
+ # Evaluate our children.
+ def evaluate(scope)
+ items = {}
- @value.each_pair do |k,v|
- key = k.respond_to?(:safeevaluate) ? k.safeevaluate(scope) : k
- items.merge!({ key => v.safeevaluate(scope) })
- end
+ @value.each_pair do |k,v|
+ key = k.respond_to?(:safeevaluate) ? k.safeevaluate(scope) : k
+ items.merge!({ key => v.safeevaluate(scope) })
+ end
- items
- end
+ items
+ end
- def merge(hash)
- case hash
- when ASTHash
- @value = @value.merge(hash.value)
- when Hash
- @value = @value.merge(hash)
- end
- end
+ def merge(hash)
+ case hash
+ when ASTHash
+ @value = @value.merge(hash.value)
+ when Hash
+ @value = @value.merge(hash)
+ end
+ end
- def to_s
- "{" + @value.collect { |v| v.collect { |a| a.to_s }.join(' => ') }.join(', ') + "}"
- end
+ def to_s
+ "{" + @value.collect { |v| v.collect { |a| a.to_s }.join(' => ') }.join(', ') + "}"
+ end
- def initialize(args)
- super(args)
- @value ||= {}
- end
+ def initialize(args)
+ super(args)
+ @value ||= {}
end
+ end
end
diff --git a/lib/puppet/parser/ast/boolean_operator.rb b/lib/puppet/parser/ast/boolean_operator.rb
index 0f7e21d2c..8481e4f8d 100644
--- a/lib/puppet/parser/ast/boolean_operator.rb
+++ b/lib/puppet/parser/ast/boolean_operator.rb
@@ -2,45 +2,45 @@ require 'puppet'
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- class BooleanOperator < AST::Branch
+ class BooleanOperator < AST::Branch
- attr_accessor :operator, :lval, :rval
+ attr_accessor :operator, :lval, :rval
- # Iterate across all of our children.
- def each
- [@lval,@rval,@operator].each { |child| yield child }
- end
+ # 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)
+ # 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
+ # 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
+ def initialize(hash)
+ super
- raise ArgumentError, "Invalid boolean operator #{@operator}" unless %w{and or}.include?(@operator)
- end
+ raise ArgumentError, "Invalid boolean operator #{@operator}" unless %w{and or}.include?(@operator)
end
+ end
end
diff --git a/lib/puppet/parser/ast/branch.rb b/lib/puppet/parser/ast/branch.rb
index 96d065e4c..73a2f674b 100644
--- a/lib/puppet/parser/ast/branch.rb
+++ b/lib/puppet/parser/ast/branch.rb
@@ -1,37 +1,37 @@
class Puppet::Parser::AST
- # The parent class of all AST objects that contain other AST objects.
- # Everything but the really simple objects descend from this. It is
- # important to note that Branch objects contain other AST objects only --
- # if you want to contain values, use a descendent of the AST::Leaf class.
- class Branch < AST
- include Enumerable
- attr_accessor :pin, :children
+ # The parent class of all AST objects that contain other AST objects.
+ # Everything but the really simple objects descend from this. It is
+ # important to note that Branch objects contain other AST objects only --
+ # if you want to contain values, use a descendent of the AST::Leaf class.
+ class Branch < AST
+ include Enumerable
+ attr_accessor :pin, :children
- # Yield each contained AST node in turn. Used mostly by 'evaluate'.
- # This definition means that I don't have to override 'evaluate'
- # every time, but each child of Branch will likely need to override
- # this method.
- def each
- @children.each { |child|
- yield child
- }
- end
+ # Yield each contained AST node in turn. Used mostly by 'evaluate'.
+ # This definition means that I don't have to override 'evaluate'
+ # every time, but each child of Branch will likely need to override
+ # this method.
+ def each
+ @children.each { |child|
+ yield child
+ }
+ end
- # Initialize our object. Largely relies on the method from the base
- # class, but also does some verification.
- def initialize(arghash)
- super(arghash)
+ # Initialize our object. Largely relies on the method from the base
+ # class, but also does some verification.
+ def initialize(arghash)
+ super(arghash)
- # Create the hash, if it was not set at initialization time.
- @children ||= []
+ # Create the hash, if it was not set at initialization time.
+ @children ||= []
- # Verify that we only got valid AST nodes.
- @children.each { |child|
- unless child.is_a?(AST)
- raise Puppet::DevError,
- "child #{child} is a #{child.class} instead of ast"
- end
- }
+ # Verify that we only got valid AST nodes.
+ @children.each { |child|
+ unless child.is_a?(AST)
+ raise Puppet::DevError,
+ "child #{child} is a #{child.class} instead of ast"
end
+ }
end
+ end
end
diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb
index 6cf36f94c..4e296e82f 100644
--- a/lib/puppet/parser/ast/caseopt.rb
+++ b/lib/puppet/parser/ast/caseopt.rb
@@ -1,64 +1,64 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # Each individual option in a case statement.
- class CaseOpt < AST::Branch
- attr_accessor :value, :statements
+ # Each individual option in a case statement.
+ class CaseOpt < AST::Branch
+ attr_accessor :value, :statements
- # CaseOpt is a bit special -- we just want the value first,
- # so that CaseStatement can compare, and then it will selectively
- # decide whether to fully evaluate this option
+ # CaseOpt is a bit special -- we just want the value first,
+ # so that CaseStatement can compare, and then it will selectively
+ # decide whether to fully evaluate this option
- def each
- [@value,@statements].each { |child| yield child }
- end
+ def each
+ [@value,@statements].each { |child| yield child }
+ end
- # Are we the default option?
- def default?
- # Cache the @default value.
- return @default if defined?(@default)
+ # Are we the default option?
+ def default?
+ # Cache the @default value.
+ return @default if defined?(@default)
- if @value.is_a?(AST::ASTArray)
- @value.each { |subval|
- if subval.is_a?(AST::Default)
- @default = true
- break
- end
- }
- else
- @default = true if @value.is_a?(AST::Default)
- end
+ if @value.is_a?(AST::ASTArray)
+ @value.each { |subval|
+ if subval.is_a?(AST::Default)
+ @default = true
+ break
+ end
+ }
+ else
+ @default = true if @value.is_a?(AST::Default)
+ end
- @default ||= false
+ @default ||= false
- @default
- end
+ @default
+ end
- # You can specify a list of values; return each in turn.
- def eachvalue(scope)
- if @value.is_a?(AST::ASTArray)
- @value.each { |subval|
- yield subval.safeevaluate(scope)
- }
- else
- yield @value.safeevaluate(scope)
- end
- end
+ # You can specify a list of values; return each in turn.
+ def eachvalue(scope)
+ if @value.is_a?(AST::ASTArray)
+ @value.each { |subval|
+ yield subval.safeevaluate(scope)
+ }
+ else
+ yield @value.safeevaluate(scope)
+ end
+ end
- def eachopt
- if @value.is_a?(AST::ASTArray)
- @value.each { |subval|
- yield subval
- }
- else
- yield @value
- end
- end
+ def eachopt
+ if @value.is_a?(AST::ASTArray)
+ @value.each { |subval|
+ yield subval
+ }
+ else
+ yield @value
+ end
+ end
- # Evaluate the actual statements; this only gets called if
- # our option matched.
- def evaluate(scope)
- @statements.safeevaluate(scope)
- end
+ # Evaluate the actual statements; this only gets called if
+ # our option matched.
+ def evaluate(scope)
+ @statements.safeevaluate(scope)
end
+ end
end
diff --git a/lib/puppet/parser/ast/casestatement.rb b/lib/puppet/parser/ast/casestatement.rb
index 0cddef0f0..8370d11f3 100644
--- a/lib/puppet/parser/ast/casestatement.rb
+++ b/lib/puppet/parser/ast/casestatement.rb
@@ -1,44 +1,44 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # The basic logical structure in Puppet. Supports a list of
- # tests and statement arrays.
- class CaseStatement < AST::Branch
- attr_accessor :test, :options, :default
+ # The basic logical structure in Puppet. Supports a list of
+ # tests and statement arrays.
+ class CaseStatement < AST::Branch
+ attr_accessor :test, :options, :default
- associates_doc
+ associates_doc
- # Short-curcuit evaluation. Return the value of the statements for
- # the first option that matches.
- def evaluate(scope)
- level = scope.ephemeral_level
+ # Short-curcuit evaluation. Return the value of the statements for
+ # the first option that matches.
+ def evaluate(scope)
+ level = scope.ephemeral_level
- value = @test.safeevaluate(scope)
+ value = @test.safeevaluate(scope)
- retvalue = nil
- found = false
+ retvalue = nil
+ found = false
- # Iterate across the options looking for a match.
- default = nil
- @options.each do |option|
- option.eachopt do |opt|
- return option.safeevaluate(scope) if opt.evaluate_match(value, scope)
- end
+ # Iterate across the options looking for a match.
+ default = nil
+ @options.each do |option|
+ option.eachopt do |opt|
+ return option.safeevaluate(scope) if opt.evaluate_match(value, scope)
+ end
- default = option if option.default?
- end
+ default = option if option.default?
+ end
- # Unless we found something, look for the default.
- return default.safeevaluate(scope) if default
+ # Unless we found something, look for the default.
+ return default.safeevaluate(scope) if default
- Puppet.debug "No true answers and no default"
- return nil
- ensure
- scope.unset_ephemeral_var(level)
- end
+ Puppet.debug "No true answers and no default"
+ return nil
+ ensure
+ scope.unset_ephemeral_var(level)
+ end
- def each
- [@test,@options].each { |child| yield child }
- end
+ def each
+ [@test,@options].each { |child| yield child }
end
+ end
end
diff --git a/lib/puppet/parser/ast/collection.rb b/lib/puppet/parser/ast/collection.rb
index 44f3b330c..09d5b4eb3 100644
--- a/lib/puppet/parser/ast/collection.rb
+++ b/lib/puppet/parser/ast/collection.rb
@@ -6,60 +6,60 @@ require 'puppet/parser/collector'
# them to the current host, yo.
class Puppet::Parser::AST
class Collection < AST::Branch
- attr_accessor :type, :query, :form
- attr_reader :override
+ attr_accessor :type, :query, :form
+ attr_reader :override
- associates_doc
+ associates_doc
- # We return an object that does a late-binding evaluation.
- def evaluate(scope)
- if self.query
- str, code = self.query.safeevaluate scope
- else
- str = code = nil
- end
+ # We return an object that does a late-binding evaluation.
+ def evaluate(scope)
+ if self.query
+ str, code = self.query.safeevaluate scope
+ else
+ str = code = nil
+ end
- newcoll = Puppet::Parser::Collector.new(scope, @type, str, code, self.form)
+ newcoll = Puppet::Parser::Collector.new(scope, @type, str, code, self.form)
- scope.compiler.add_collection(newcoll)
+ scope.compiler.add_collection(newcoll)
- # overrides if any
- # Evaluate all of the specified params.
- if @override
- params = @override.collect do |param|
- param.safeevaluate(scope)
- end
+ # overrides if any
+ # Evaluate all of the specified params.
+ if @override
+ params = @override.collect do |param|
+ param.safeevaluate(scope)
+ end
- newcoll.add_override(
+ newcoll.add_override(
- :parameters => params,
- :file => @file,
- :line => @line,
- :source => scope.source,
+ :parameters => params,
+ :file => @file,
+ :line => @line,
+ :source => scope.source,
- :scope => scope
- )
- end
-
- newcoll
+ :scope => scope
+ )
end
- # Handle our parameter ourselves
- def override=(override)
- if override.is_a?(AST::ASTArray)
- @override = override
- else
+ newcoll
+ end
+
+ # Handle our parameter ourselves
+ def override=(override)
+ if override.is_a?(AST::ASTArray)
+ @override = override
+ else
- @override = AST::ASTArray.new(
+ @override = AST::ASTArray.new(
- :line => override.line,
- :file => override.file,
+ :line => override.line,
+ :file => override.file,
- :children => [override]
- )
- end
+ :children => [override]
+ )
end
+ end
end
end
diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb
index f71b53d46..f912b4b33 100644
--- a/lib/puppet/parser/ast/collexpr.rb
+++ b/lib/puppet/parser/ast/collexpr.rb
@@ -6,81 +6,81 @@ require 'puppet/parser/collector'
# them to the current host, yo.
class Puppet::Parser::AST
class CollExpr < AST::Branch
- attr_accessor :test1, :test2, :oper, :form, :type, :parens
+ attr_accessor :test1, :test2, :oper, :form, :type, :parens
- # We return an object that does a late-binding evaluation.
- def evaluate(scope)
- # Make sure our contained expressions have all the info they need.
- [@test1, @test2].each do |t|
- if t.is_a?(self.class)
- t.form ||= self.form
- t.type ||= self.type
- end
- end
-
- # The code is only used for virtual lookups
- str1, code1 = @test1.safeevaluate scope
- str2, code2 = @test2.safeevaluate scope
-
- # First build up the virtual code.
- # If we're a conjunction operator, then we're calling code. I did
- # some speed comparisons, and it's at least twice as fast doing these
- # case statements as doing an eval here.
- code = proc do |resource|
- case @oper
- when "and"; code1.call(resource) and code2.call(resource)
- when "or"; code1.call(resource) or code2.call(resource)
- when "=="
- if str1 == "tag"
- resource.tagged?(str2)
- else
- if resource[str1].is_a?(Array)
- resource[str1].include?(str2)
- else
- resource[str1] == str2
- end
- end
- when "!="; resource[str1] != str2
- end
- end
-
- # Now build up the rails conditions code
- if self.parens and self.form == :exported
- Puppet.warning "Parentheses are ignored in Rails searches"
- end
+ # We return an object that does a late-binding evaluation.
+ def evaluate(scope)
+ # Make sure our contained expressions have all the info they need.
+ [@test1, @test2].each do |t|
+ if t.is_a?(self.class)
+ t.form ||= self.form
+ t.type ||= self.type
+ end
+ end
- case @oper
- when "and", "or"
- if form == :exported
- raise Puppet::ParseError, "Puppet does not currently support collecting exported resources with more than one condition"
- end
- oper = @oper.upcase
- when "=="; oper = "="
- else
- oper = @oper
- end
+ # The code is only used for virtual lookups
+ str1, code1 = @test1.safeevaluate scope
+ str2, code2 = @test2.safeevaluate scope
- if oper == "=" or oper == "!="
- # Add the rails association info where necessary
- case str1
- when "title"
- str = "title #{oper} '#{str2}'"
- when "tag"
- str = "puppet_tags.name #{oper} '#{str2}'"
- else
- str = "param_values.value #{oper} '#{str2}' and param_names.name = '#{str1}'"
- end
+ # First build up the virtual code.
+ # If we're a conjunction operator, then we're calling code. I did
+ # some speed comparisons, and it's at least twice as fast doing these
+ # case statements as doing an eval here.
+ code = proc do |resource|
+ case @oper
+ when "and"; code1.call(resource) and code2.call(resource)
+ when "or"; code1.call(resource) or code2.call(resource)
+ when "=="
+ if str1 == "tag"
+ resource.tagged?(str2)
else
- str = "(#{str1}) #{oper} (#{str2})"
+ if resource[str1].is_a?(Array)
+ resource[str1].include?(str2)
+ else
+ resource[str1] == str2
+ end
end
+ when "!="; resource[str1] != str2
+ end
+ end
- return str, code
+ # Now build up the rails conditions code
+ if self.parens and self.form == :exported
+ Puppet.warning "Parentheses are ignored in Rails searches"
end
- def initialize(hash = {})
- super
+ case @oper
+ when "and", "or"
+ if form == :exported
+ raise Puppet::ParseError, "Puppet does not currently support collecting exported resources with more than one condition"
+ end
+ oper = @oper.upcase
+ when "=="; oper = "="
+ else
+ oper = @oper
+ end
- raise ArgumentError, "Invalid operator #{@oper}" unless %w{== != and or}.include?(@oper)
+ if oper == "=" or oper == "!="
+ # Add the rails association info where necessary
+ case str1
+ when "title"
+ str = "title #{oper} '#{str2}'"
+ when "tag"
+ str = "puppet_tags.name #{oper} '#{str2}'"
+ else
+ str = "param_values.value #{oper} '#{str2}' and param_names.name = '#{str1}'"
+ end
+ else
+ str = "(#{str1}) #{oper} (#{str2})"
end
+
+ return str, code
+ end
+
+ def initialize(hash = {})
+ super
+
+ raise ArgumentError, "Invalid operator #{@oper}" unless %w{== != and or}.include?(@oper)
+ end
end
end
diff --git a/lib/puppet/parser/ast/comparison_operator.rb b/lib/puppet/parser/ast/comparison_operator.rb
index e8b21d45f..c8694bbff 100644
--- a/lib/puppet/parser/ast/comparison_operator.rb
+++ b/lib/puppet/parser/ast/comparison_operator.rb
@@ -2,38 +2,38 @@ 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)
-
- # convert to number if operands are number
- lval = Puppet::Parser::Scope.number?(lval) || lval
- rval = Puppet::Parser::Scope.number?(rval) || rval
-
- # return result
- unless @operator == '!='
- lval.send(@operator,rval)
- else
- lval != rval
- end
- end
-
- def initialize(hash)
- super
-
- raise ArgumentError, "Invalid comparison operator #{@operator}" unless %w{== != < > <= >=}.include?(@operator)
- end
+ 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)
+
+ # convert to number if operands are number
+ lval = Puppet::Parser::Scope.number?(lval) || lval
+ rval = Puppet::Parser::Scope.number?(rval) || rval
+
+ # return result
+ unless @operator == '!='
+ lval.send(@operator,rval)
+ else
+ lval != rval
+ end
+ end
+
+ def initialize(hash)
+ super
+
+ raise ArgumentError, "Invalid comparison operator #{@operator}" unless %w{== != < > <= >=}.include?(@operator)
end
+ end
end
diff --git a/lib/puppet/parser/ast/else.rb b/lib/puppet/parser/ast/else.rb
index 2da9191c8..172149116 100644
--- a/lib/puppet/parser/ast/else.rb
+++ b/lib/puppet/parser/ast/else.rb
@@ -1,22 +1,22 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # A separate ElseIf statement; can function as an 'else' if there's no
- # test.
- class Else < AST::Branch
+ # A separate ElseIf statement; can function as an 'else' if there's no
+ # test.
+ class Else < AST::Branch
- associates_doc
+ associates_doc
- attr_accessor :statements
+ attr_accessor :statements
- def each
- yield @statements
- end
+ def each
+ yield @statements
+ end
- # Evaluate the actual statements; this only gets called if
- # our test was true matched.
- def evaluate(scope)
- @statements.safeevaluate(scope)
- end
+ # Evaluate the actual statements; this only gets called if
+ # our test was true matched.
+ def evaluate(scope)
+ @statements.safeevaluate(scope)
end
+ end
end
diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb
index 6f6c869f5..602016c75 100644
--- a/lib/puppet/parser/ast/function.rb
+++ b/lib/puppet/parser/ast/function.rb
@@ -1,51 +1,51 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # An AST object to call a function.
- class Function < AST::Branch
+ # An AST object to call a function.
+ class Function < AST::Branch
- associates_doc
+ associates_doc
- attr_accessor :name, :arguments
+ attr_accessor :name, :arguments
- @settor = true
+ @settor = true
- def evaluate(scope)
+ def evaluate(scope)
- # Make sure it's a defined function
- raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name)
+ # Make sure it's a defined function
+ raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name)
- # Now check that it's been used correctly
- case @ftype
- when :rvalue
- raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name)
- when :statement
- if Puppet::Parser::Functions.rvalue?(@name)
- raise Puppet::ParseError,
- "Function '#{@name}' must be the value of a statement"
- end
- else
- raise Puppet::DevError, "Invalid function type #{@ftype.inspect}"
- end
+ # Now check that it's been used correctly
+ case @ftype
+ when :rvalue
+ raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name)
+ when :statement
+ if Puppet::Parser::Functions.rvalue?(@name)
+ raise Puppet::ParseError,
+ "Function '#{@name}' must be the value of a statement"
+ end
+ else
+ raise Puppet::DevError, "Invalid function type #{@ftype.inspect}"
+ end
- # We don't need to evaluate the name, because it's plaintext
- args = @arguments.safeevaluate(scope)
+ # We don't need to evaluate the name, because it's plaintext
+ args = @arguments.safeevaluate(scope)
- scope.send("function_#{@name}", args)
- end
+ scope.send("function_#{@name}", args)
+ end
- def initialize(hash)
- @ftype = hash[:ftype] || :rvalue
- hash.delete(:ftype) if hash.include? :ftype
+ def initialize(hash)
+ @ftype = hash[:ftype] || :rvalue
+ hash.delete(:ftype) if hash.include? :ftype
- super(hash)
+ super(hash)
- # Lastly, check the parity
- end
+ # Lastly, check the parity
+ end
- def to_s
- args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments
- "#{name}(#{args})"
- end
+ def to_s
+ args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments
+ "#{name}(#{args})"
end
+ end
end
diff --git a/lib/puppet/parser/ast/ifstatement.rb b/lib/puppet/parser/ast/ifstatement.rb
index cbb61bf9c..7fd8a576a 100644
--- a/lib/puppet/parser/ast/ifstatement.rb
+++ b/lib/puppet/parser/ast/ifstatement.rb
@@ -1,34 +1,34 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # A basic 'if/elsif/else' statement.
- class IfStatement < AST::Branch
+ # A basic 'if/elsif/else' statement.
+ class IfStatement < AST::Branch
- associates_doc
+ associates_doc
- attr_accessor :test, :else, :statements
+ attr_accessor :test, :else, :statements
- def each
- [@test,@else,@statements].each { |child| yield child }
- end
+ def each
+ [@test,@else,@statements].each { |child| yield child }
+ end
- # Short-curcuit evaluation. If we're true, evaluate our statements,
- # else if there's an 'else' setting, evaluate it.
- # the first option that matches.
- def evaluate(scope)
- level = scope.ephemeral_level
- value = @test.safeevaluate(scope)
+ # Short-curcuit evaluation. If we're true, evaluate our statements,
+ # else if there's an 'else' setting, evaluate it.
+ # the first option that matches.
+ def evaluate(scope)
+ level = scope.ephemeral_level
+ value = @test.safeevaluate(scope)
- # let's emulate a new scope for each branches
- begin
- if Puppet::Parser::Scope.true?(value)
- return @statements.safeevaluate(scope)
- else
- return defined?(@else) ? @else.safeevaluate(scope) : nil
- end
- ensure
- scope.unset_ephemeral_var(level)
- end
+ # let's emulate a new scope for each branches
+ begin
+ if Puppet::Parser::Scope.true?(value)
+ return @statements.safeevaluate(scope)
+ else
+ return defined?(@else) ? @else.safeevaluate(scope) : nil
end
+ ensure
+ scope.unset_ephemeral_var(level)
+ end
end
+ end
end
diff --git a/lib/puppet/parser/ast/in_operator.rb b/lib/puppet/parser/ast/in_operator.rb
index 1b17b1006..2a163e726 100644
--- a/lib/puppet/parser/ast/in_operator.rb
+++ b/lib/puppet/parser/ast/in_operator.rb
@@ -2,23 +2,23 @@ require 'puppet'
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- class InOperator < AST::Branch
+ class InOperator < AST::Branch
- attr_accessor :lval, :rval
+ attr_accessor :lval, :rval
- # Returns a boolean which is the result of the 'in' operation
- # of lval and rval operands
- def evaluate(scope)
+ # Returns a boolean which is the result of the 'in' operation
+ # of lval and rval operands
+ def evaluate(scope)
- # evaluate the operands, should return a boolean value
- lval = @lval.safeevaluate(scope)
- raise ArgumentError, "'#{lval}' from left operand of 'in' expression is not a string" unless lval.is_a?(::String)
+ # evaluate the operands, should return a boolean value
+ lval = @lval.safeevaluate(scope)
+ raise ArgumentError, "'#{lval}' from left operand of 'in' expression is not a string" unless lval.is_a?(::String)
- rval = @rval.safeevaluate(scope)
- unless rval.respond_to?(:include?)
- raise ArgumentError, "'#{rval}' from right operand of 'in' expression is not of a supported type (string, array or hash)"
- end
- rval.include?(lval)
- end
+ rval = @rval.safeevaluate(scope)
+ unless rval.respond_to?(:include?)
+ raise ArgumentError, "'#{rval}' from right operand of 'in' expression is not of a supported type (string, array or hash)"
+ end
+ rval.include?(lval)
end
+ end
end
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index a62edc61e..3b9163d9c 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -1,224 +1,224 @@
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
-
- # evaluate ourselves, and match
- def evaluate_match(value, scope)
- obj = self.safeevaluate(scope)
+ # 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
- obj = obj.downcase if obj.respond_to?(:downcase)
- value = value.downcase if value.respond_to?(:downcase)
+ # evaluate ourselves, and match
+ def evaluate_match(value, scope)
+ obj = self.safeevaluate(scope)
- # "" == undef for case/selector/if
- obj == value or (obj == "" and value == :undef)
- end
+ obj = obj.downcase if obj.respond_to?(:downcase)
+ value = value.downcase if value.respond_to?(:downcase)
- def match(value)
- @value == value
- end
+ # "" == undef for case/selector/if
+ obj == value or (obj == "" and value == :undef)
+ end
- def to_s
- @value.to_s unless @value.nil?
- end
+ def match(value)
+ @value == value
end
- # The boolean class. True or false. Converts the string it receives
- # to a Ruby boolean.
- class Boolean < AST::Leaf
+ def to_s
+ @value.to_s unless @value.nil?
+ end
+ end
- # Use the parent method, but then convert to a real boolean.
- def initialize(hash)
- super
+ # The boolean class. True or false. Converts the string it receives
+ # to a Ruby boolean.
+ class Boolean < AST::Leaf
- unless @value == true or @value == false
- raise Puppet::DevError,
- "'#{@value}' is not a boolean"
- end
- @value
- end
+ # Use the parent method, but then convert to a real boolean.
+ def initialize(hash)
+ super
- def to_s
- @value ? "true" : "false"
- end
+ unless @value == true or @value == false
+ raise Puppet::DevError,
+ "'#{@value}' is not a boolean"
+ end
+ @value
end
- # The base string class.
- class String < AST::Leaf
- def evaluate(scope)
- @value
- end
+ def to_s
+ @value ? "true" : "false"
+ end
+ end
- def to_s
- "\"#{@value}\""
- end
+ # The base string class.
+ class String < AST::Leaf
+ def evaluate(scope)
+ @value
end
- # An uninterpreted string.
- class FlatString < AST::Leaf
- def evaluate(scope)
- @value
- end
+ def to_s
+ "\"#{@value}\""
+ end
+ end
- def to_s
- "\"#{@value}\""
- end
+ # An uninterpreted string.
+ class FlatString < AST::Leaf
+ def evaluate(scope)
+ @value
end
- class Concat < AST::Leaf
- def evaluate(scope)
- @value.collect { |x| x.evaluate(scope) }.join
- end
+ def to_s
+ "\"#{@value}\""
+ end
+ end
- def to_s
- "concat(#{@value.join(',')})"
- end
+ class Concat < AST::Leaf
+ def evaluate(scope)
+ @value.collect { |x| x.evaluate(scope) }.join
end
- # The 'default' option on case statements and selectors.
- class Default < AST::Leaf; end
+ def to_s
+ "concat(#{@value.join(',')})"
+ end
+ end
- # Capitalized words; used mostly for type-defaults, but also
- # get returned by the lexer any other time an unquoted capitalized
- # word is found.
- class Type < AST::Leaf; end
+ # The 'default' option on case statements and selectors.
+ class Default < AST::Leaf; end
- # Lower-case words.
- class Name < AST::Leaf; end
+ # Capitalized words; used mostly for type-defaults, but also
+ # get returned by the lexer any other time an unquoted capitalized
+ # word is found.
+ class Type < AST::Leaf; end
- # double-colon separated class names
- class ClassName < AST::Leaf; end
+ # Lower-case words.
+ class Name < AST::Leaf; end
- # undef values; equiv to nil
- class Undef < AST::Leaf; end
+ # double-colon separated class names
+ class ClassName < AST::Leaf; end
- # Host names, either fully qualified or just the short name, or even a regex
- class HostName < AST::Leaf
- def initialize(hash)
- super
+ # undef values; equiv to nil
+ class Undef < AST::Leaf; end
- # Note that this is an AST::Regex, not a Regexp
- @value = @value.to_s.downcase unless @value.is_a?(Regex)
- if @value =~ /[^-\w.]/
- raise Puppet::DevError,
- "'#{@value}' is not a valid hostname"
- end
- end
+ # Host names, either fully qualified or just the short name, or even a regex
+ class HostName < AST::Leaf
+ def initialize(hash)
+ super
- # 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 = value.value if value.is_a?(HostName)
- @value.eql?(value)
- end
+ # Note that this is an AST::Regex, not a Regexp
+ @value = @value.to_s.downcase unless @value.is_a?(Regex)
+ if @value =~ /[^-\w.]/
+ raise Puppet::DevError,
+ "'#{@value}' is not a valid hostname"
+ end
+ end
- def hash
- @value.hash
- 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 = value.value if value.is_a?(HostName)
+ @value.eql?(value)
+ end
- def to_s
- @value.to_s
- end
+ def hash
+ @value.hash
end
- # A simple variable. This object is only used during interpolation;
- # the VarDef class is used for assignment.
- class Variable < Name
- # Looks up the value of the object in the scope tree (does
- # not include syntactical constructs, like '$' and '{}').
- def evaluate(scope)
- parsewrap do
- if (var = scope.lookupvar(@value, false)) == :undefined
- var = :undef
- end
- var
- end
- end
+ def to_s
+ @value.to_s
+ end
+ end
+
+ # A simple variable. This object is only used during interpolation;
+ # the VarDef class is used for assignment.
+ class Variable < Name
+ # Looks up the value of the object in the scope tree (does
+ # not include syntactical constructs, like '$' and '{}').
+ def evaluate(scope)
+ parsewrap do
+ if (var = scope.lookupvar(@value, false)) == :undefined
+ var = :undef
+ end
+ var
+ end
+ end
- def to_s
- "\$#{value}"
- end
+ def to_s
+ "\$#{value}"
end
+ end
- class HashOrArrayAccess < AST::Leaf
- attr_accessor :variable, :key
+ class HashOrArrayAccess < AST::Leaf
+ attr_accessor :variable, :key
- def evaluate_container(scope)
- container = variable.respond_to?(:evaluate) ? variable.safeevaluate(scope) : variable
- (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container)
- end
+ def evaluate_container(scope)
+ container = variable.respond_to?(:evaluate) ? variable.safeevaluate(scope) : variable
+ (container.is_a?(Hash) or container.is_a?(Array)) ? container : scope.lookupvar(container)
+ end
- def evaluate_key(scope)
- key.respond_to?(:evaluate) ? key.safeevaluate(scope) : key
- end
+ def evaluate_key(scope)
+ key.respond_to?(:evaluate) ? key.safeevaluate(scope) : key
+ end
- def evaluate(scope)
- object = evaluate_container(scope)
+ def evaluate(scope)
+ object = evaluate_container(scope)
- raise Puppet::ParseError, "#{variable} is not an hash or array when accessing it with #{accesskey}" unless object.is_a?(Hash) or object.is_a?(Array)
+ raise Puppet::ParseError, "#{variable} is not an hash or array when accessing it with #{accesskey}" unless object.is_a?(Hash) or object.is_a?(Array)
- object[evaluate_key(scope)]
- end
+ object[evaluate_key(scope)]
+ end
- # Assign value to this hashkey or array index
- def assign(scope, value)
- object = evaluate_container(scope)
- accesskey = evaluate_key(scope)
+ # Assign value to this hashkey or array index
+ def assign(scope, value)
+ object = evaluate_container(scope)
+ accesskey = evaluate_key(scope)
- if object.is_a?(Hash) and object.include?(accesskey)
- raise Puppet::ParseError, "Assigning to the hash '#{variable}' with an existing key '#{accesskey}' is forbidden"
- end
+ if object.is_a?(Hash) and object.include?(accesskey)
+ raise Puppet::ParseError, "Assigning to the hash '#{variable}' with an existing key '#{accesskey}' is forbidden"
+ end
- # assign to hash or array
- object[accesskey] = value
- end
+ # assign to hash or array
+ object[accesskey] = value
+ end
- def to_s
- "\$#{variable.to_s}[#{key.to_s}]"
- end
+ def to_s
+ "\$#{variable.to_s}[#{key.to_s}]"
end
+ end
- class Regex < AST::Leaf
- def initialize(hash)
- super
- @value = Regexp.new(@value) unless @value.is_a?(Regexp)
- end
+ class Regex < AST::Leaf
+ def initialize(hash)
+ super
+ @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
+ # 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 evaluate_match(value, scope, options = {})
- value = value.is_a?(String) ? value : value.to_s
+ def evaluate_match(value, scope, options = {})
+ value = value.is_a?(String) ? value : value.to_s
- if matched = @value.match(value)
- scope.ephemeral_from(matched, options[:file], options[:line])
- end
- matched
- end
+ if matched = @value.match(value)
+ scope.ephemeral_from(matched, options[:file], options[:line])
+ end
+ matched
+ end
- def match(value)
- @value.match(value)
- end
+ def match(value)
+ @value.match(value)
+ end
- def to_s
- "/#{@value.source}/"
- end
+ def to_s
+ "/#{@value.source}/"
end
+ end
end
diff --git a/lib/puppet/parser/ast/match_operator.rb b/lib/puppet/parser/ast/match_operator.rb
index 2ab2befd4..6207a8c2c 100644
--- a/lib/puppet/parser/ast/match_operator.rb
+++ b/lib/puppet/parser/ast/match_operator.rb
@@ -2,27 +2,27 @@ require 'puppet'
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- class MatchOperator < AST::Branch
+ class MatchOperator < AST::Branch
- attr_accessor :lval, :rval, :operator
+ attr_accessor :lval, :rval, :operator
- # Iterate across all of our children.
- def each
- [@lval,@rval].each { |child| yield child }
- end
+ # Iterate across all of our children.
+ def each
+ [@lval,@rval].each { |child| yield child }
+ end
- # Returns a boolean which is the result of the boolean operation
- # of lval and rval operands
- def evaluate(scope)
- lval = @lval.safeevaluate(scope)
+ # Returns a boolean which is the result of the boolean operation
+ # of lval and rval operands
+ def evaluate(scope)
+ lval = @lval.safeevaluate(scope)
- return(rval.evaluate_match(lval, scope) ? @operator == "=~" : @operator == "!~")
- end
+ return(rval.evaluate_match(lval, scope) ? @operator == "=~" : @operator == "!~")
+ end
- def initialize(hash)
- super
+ def initialize(hash)
+ super
- raise ArgumentError, "Invalid regexp operator #{@operator}" unless %w{!~ =~}.include?(@operator)
- end
+ raise ArgumentError, "Invalid regexp operator #{@operator}" unless %w{!~ =~}.include?(@operator)
end
+ end
end
diff --git a/lib/puppet/parser/ast/minus.rb b/lib/puppet/parser/ast/minus.rb
index 40f64336c..d7a362aa1 100644
--- a/lib/puppet/parser/ast/minus.rb
+++ b/lib/puppet/parser/ast/minus.rb
@@ -4,20 +4,20 @@ 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
+ class Minus < AST::Branch
+ attr_accessor :value
- def each
- yield @value
- end
+ 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 #{val} is not a number"
- end
- -val
- end
+ def evaluate(scope)
+ val = @value.safeevaluate(scope)
+ val = Puppet::Parser::Scope.number?(val)
+ if val == nil
+ raise ArgumentError, "minus operand #{val} is not a number"
+ end
+ -val
end
+ end
end
diff --git a/lib/puppet/parser/ast/nop.rb b/lib/puppet/parser/ast/nop.rb
index ea5232043..bf35c6a5c 100644
--- a/lib/puppet/parser/ast/nop.rb
+++ b/lib/puppet/parser/ast/nop.rb
@@ -1,11 +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
+ # 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
index 24d5e838b..30fa6d503 100644
--- a/lib/puppet/parser/ast/not.rb
+++ b/lib/puppet/parser/ast/not.rb
@@ -4,16 +4,16 @@ 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
+ class Not < AST::Branch
+ attr_accessor :value
- def each
- yield @value
- end
+ def each
+ yield @value
+ end
- def evaluate(scope)
- val = @value.safeevaluate(scope)
- ! Puppet::Parser::Scope.true?(val)
- end
+ def evaluate(scope)
+ val = @value.safeevaluate(scope)
+ ! Puppet::Parser::Scope.true?(val)
end
+ end
end
diff --git a/lib/puppet/parser/ast/relationship.rb b/lib/puppet/parser/ast/relationship.rb
index 9f9f6fc1d..a7134a04f 100644
--- a/lib/puppet/parser/ast/relationship.rb
+++ b/lib/puppet/parser/ast/relationship.rb
@@ -3,58 +3,58 @@ require 'puppet/parser/ast/branch'
require 'puppet/parser/relationship'
class Puppet::Parser::AST::Relationship < Puppet::Parser::AST::Branch
- RELATIONSHIP_TYPES = %w{-> <- ~> <~}
+ RELATIONSHIP_TYPES = %w{-> <- ~> <~}
- attr_accessor :left, :right, :arrow, :type
+ attr_accessor :left, :right, :arrow, :type
- def actual_left
- chained? ? left.right : left
- end
+ def actual_left
+ chained? ? left.right : left
+ end
- # Evaluate our object, but just return a simple array of the type
- # and name.
- def evaluate(scope)
- if chained?
- real_left = left.safeevaluate(scope)
- left_dep = left_dep.shift if left_dep.is_a?(Array)
- else
- real_left = left.safeevaluate(scope)
- end
- real_right = right.safeevaluate(scope)
-
- source, target = sides2edge(real_left, real_right)
- result = Puppet::Parser::Relationship.new(source, target, type)
- scope.compiler.add_relationship(result)
- real_right
+ # Evaluate our object, but just return a simple array of the type
+ # and name.
+ def evaluate(scope)
+ if chained?
+ real_left = left.safeevaluate(scope)
+ left_dep = left_dep.shift if left_dep.is_a?(Array)
+ else
+ real_left = left.safeevaluate(scope)
end
+ real_right = right.safeevaluate(scope)
- def initialize(left, right, arrow, args = {})
- super(args)
- unless RELATIONSHIP_TYPES.include?(arrow)
- raise ArgumentError, "Invalid relationship type #{arrow.inspect}; valid types are #{RELATIONSHIP_TYPES.collect { |r| r.to_s }.join(", ")}"
- end
- @left, @right, @arrow = left, right, arrow
- end
+ source, target = sides2edge(real_left, real_right)
+ result = Puppet::Parser::Relationship.new(source, target, type)
+ scope.compiler.add_relationship(result)
+ real_right
+ end
- def type
- subscription? ? :subscription : :relationship
+ def initialize(left, right, arrow, args = {})
+ super(args)
+ unless RELATIONSHIP_TYPES.include?(arrow)
+ raise ArgumentError, "Invalid relationship type #{arrow.inspect}; valid types are #{RELATIONSHIP_TYPES.collect { |r| r.to_s }.join(", ")}"
end
+ @left, @right, @arrow = left, right, arrow
+ end
- def sides2edge(left, right)
- out_edge? ? [left, right] : [right, left]
- end
+ def type
+ subscription? ? :subscription : :relationship
+ end
- private
+ def sides2edge(left, right)
+ out_edge? ? [left, right] : [right, left]
+ end
- def chained?
- left.is_a?(self.class)
- end
+ private
- def out_edge?
- ["->", "~>"].include?(arrow)
- end
+ def chained?
+ left.is_a?(self.class)
+ end
- def subscription?
- ["~>", "<~"].include?(arrow)
- end
+ def out_edge?
+ ["->", "~>"].include?(arrow)
+ end
+
+ def subscription?
+ ["~>", "<~"].include?(arrow)
+ end
end
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 01b9370ff..1b063c984 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -5,73 +5,73 @@ require 'puppet/parser/ast/resource_reference'
class Puppet::Parser::AST
class Resource < AST::ResourceReference
- associates_doc
+ associates_doc
- attr_accessor :title, :type, :exported, :virtual
- attr_reader :parameters
+ attr_accessor :title, :type, :exported, :virtual
+ attr_reader :parameters
- # Does not actually return an object; instead sets an object
- # in the current scope.
- def evaluate(scope)
- # Evaluate all of the specified params.
- paramobjects = parameters.collect { |param|
- param.safeevaluate(scope)
- }
+ # Does not actually return an object; instead sets an object
+ # in the current scope.
+ def evaluate(scope)
+ # Evaluate all of the specified params.
+ paramobjects = parameters.collect { |param|
+ param.safeevaluate(scope)
+ }
- resource_titles = @title.safeevaluate(scope)
+ resource_titles = @title.safeevaluate(scope)
- # it's easier to always use an array, even for only one name
- resource_titles = [resource_titles] unless resource_titles.is_a?(Array)
+ # it's easier to always use an array, even for only one name
+ resource_titles = [resource_titles] unless resource_titles.is_a?(Array)
- # We want virtual to be true if exported is true. We can't
- # just set :virtual => self.virtual in the initialization,
- # because sometimes the :virtual attribute is set *after*
- # :exported, in which case it clobbers :exported if :exported
- # is true. Argh, this was a very tough one to track down.
- virt = self.virtual || self.exported
+ # We want virtual to be true if exported is true. We can't
+ # just set :virtual => self.virtual in the initialization,
+ # because sometimes the :virtual attribute is set *after*
+ # :exported, in which case it clobbers :exported if :exported
+ # is true. Argh, this was a very tough one to track down.
+ virt = self.virtual || self.exported
- # This is where our implicit iteration takes place; if someone
- # passed an array as the name, then we act just like the called us
- # many times.
- resource_titles.flatten.collect { |resource_title|
- exceptwrap :type => Puppet::ParseError do
+ # This is where our implicit iteration takes place; if someone
+ # passed an array as the name, then we act just like the called us
+ # many times.
+ resource_titles.flatten.collect { |resource_title|
+ exceptwrap :type => Puppet::ParseError do
- resource = Puppet::Parser::Resource.new(
- type, resource_title,
- :parameters => paramobjects,
- :file => self.file,
- :line => self.line,
- :exported => self.exported,
- :virtual => virt,
- :source => scope.source,
- :scope => scope,
+ resource = Puppet::Parser::Resource.new(
+ type, resource_title,
+ :parameters => paramobjects,
+ :file => self.file,
+ :line => self.line,
+ :exported => self.exported,
+ :virtual => virt,
+ :source => scope.source,
+ :scope => scope,
- :strict => true
- )
+ :strict => true
+ )
- # And then store the resource in the compiler.
- # At some point, we need to switch all of this to return
- # resources instead of storing them like this.
- scope.compiler.add_resource(scope, resource)
- resource
- end
- }.reject { |resource| resource.nil? }
- end
+ # And then store the resource in the compiler.
+ # At some point, we need to switch all of this to return
+ # resources instead of storing them like this.
+ scope.compiler.add_resource(scope, resource)
+ resource
+ end
+ }.reject { |resource| resource.nil? }
+ end
- # Set the parameters for our object.
- def parameters=(params)
- if params.is_a?(AST::ASTArray)
- @parameters = params
- else
+ # Set the parameters for our object.
+ def parameters=(params)
+ if params.is_a?(AST::ASTArray)
+ @parameters = params
+ else
- @parameters = AST::ASTArray.new(
+ @parameters = AST::ASTArray.new(
- :line => params.line,
- :file => params.file,
+ :line => params.line,
+ :file => params.file,
- :children => [params]
- )
- end
+ :children => [params]
+ )
end
+ end
end
end
diff --git a/lib/puppet/parser/ast/resource_defaults.rb b/lib/puppet/parser/ast/resource_defaults.rb
index aec86d02d..812b979e9 100644
--- a/lib/puppet/parser/ast/resource_defaults.rb
+++ b/lib/puppet/parser/ast/resource_defaults.rb
@@ -1,24 +1,24 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # A statement syntactically similar to an ResourceDef, but uses a
- # capitalized object type and cannot have a name.
- class ResourceDefaults < AST::Branch
- attr_accessor :type, :parameters
+ # A statement syntactically similar to an ResourceDef, but uses a
+ # capitalized object type and cannot have a name.
+ class ResourceDefaults < AST::Branch
+ attr_accessor :type, :parameters
- associates_doc
+ associates_doc
- # As opposed to ResourceDef, this stores each default for the given
- # object type.
- def evaluate(scope)
- # Use a resource reference to canonize the type
- ref = Puppet::Resource.new(@type, "whatever")
- type = ref.type
- params = @parameters.safeevaluate(scope)
+ # As opposed to ResourceDef, this stores each default for the given
+ # object type.
+ def evaluate(scope)
+ # Use a resource reference to canonize the type
+ ref = Puppet::Resource.new(@type, "whatever")
+ type = ref.type
+ params = @parameters.safeevaluate(scope)
- parsewrap do
- scope.setdefaults(type, params)
- end
- end
+ parsewrap do
+ scope.setdefaults(type, params)
+ end
end
+ end
end
diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb
index 7f7047dd9..e0be889ff 100644
--- a/lib/puppet/parser/ast/resource_override.rb
+++ b/lib/puppet/parser/ast/resource_override.rb
@@ -1,68 +1,68 @@
require 'puppet/parser/ast/resource'
class Puppet::Parser::AST
- # Set a parameter on a resource specification created somewhere else in the
- # configuration. The object is responsible for verifying that this is allowed.
- class ResourceOverride < Resource
+ # Set a parameter on a resource specification created somewhere else in the
+ # configuration. The object is responsible for verifying that this is allowed.
+ class ResourceOverride < Resource
- associates_doc
+ associates_doc
- attr_accessor :object
- attr_reader :parameters
+ attr_accessor :object
+ attr_reader :parameters
- # Iterate across all of our children.
- def each
- [@object,@parameters].flatten.each { |param|
- #Puppet.debug("yielding param #{param}")
- yield param
- }
- end
+ # Iterate across all of our children.
+ def each
+ [@object,@parameters].flatten.each { |param|
+ #Puppet.debug("yielding param #{param}")
+ yield param
+ }
+ end
- # Does not actually return an object; instead sets an object
- # in the current scope.
- def evaluate(scope)
- # Get our object reference.
- resource = @object.safeevaluate(scope)
+ # Does not actually return an object; instead sets an object
+ # in the current scope.
+ def evaluate(scope)
+ # Get our object reference.
+ resource = @object.safeevaluate(scope)
- hash = {}
+ hash = {}
- # Evaluate all of the specified params.
- params = @parameters.collect { |param|
- param.safeevaluate(scope)
- }
+ # Evaluate all of the specified params.
+ params = @parameters.collect { |param|
+ param.safeevaluate(scope)
+ }
- # Now we just create a normal resource, but we call a very different
- # method on the scope.
- resource = [resource] unless resource.is_a?(Array)
+ # Now we just create a normal resource, but we call a very different
+ # method on the scope.
+ resource = [resource] unless resource.is_a?(Array)
- resource = resource.collect do |r|
+ resource = resource.collect do |r|
- res = Puppet::Parser::Resource.new(
- r.type, r.title,
- :parameters => params,
- :file => file,
- :line => line,
- :source => scope.source,
+ res = Puppet::Parser::Resource.new(
+ r.type, r.title,
+ :parameters => params,
+ :file => file,
+ :line => line,
+ :source => scope.source,
- :scope => scope
- )
+ :scope => scope
+ )
- # Now we tell the scope that it's an override, and it behaves as
- # necessary.
- scope.compiler.add_override(res)
+ # 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.length == 1 ? resource.pop : resource)
- end
+ res
+ end
+ # decapsulate array in case of only one item
+ return(resource.length == 1 ? resource.pop : resource)
+ end
- # Create our ResourceDef. Handles type checking for us.
- def initialize(hash)
- @checked = false
- super
+ # Create our ResourceDef. Handles type checking for us.
+ def initialize(hash)
+ @checked = false
+ super
- #self.typecheck(@type.value)
- end
+ #self.typecheck(@type.value)
end
+ end
end
diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb
index 37e82d568..5d8334335 100644
--- a/lib/puppet/parser/ast/resource_reference.rb
+++ b/lib/puppet/parser/ast/resource_reference.rb
@@ -2,20 +2,20 @@ require 'puppet/parser/ast'
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch
- attr_accessor :title, :type
+ attr_accessor :title, :type
- # Evaluate our object, but just return a simple array of the type
- # and name.
- def evaluate(scope)
- titles = Array(title.safeevaluate(scope)).collect { |t| Puppet::Resource.new(type, t, :namespaces => scope.namespaces) }
- return(titles.length == 1 ? titles.pop : titles)
- end
+ # Evaluate our object, but just return a simple array of the type
+ # and name.
+ def evaluate(scope)
+ titles = Array(title.safeevaluate(scope)).collect { |t| Puppet::Resource.new(type, t, :namespaces => scope.namespaces) }
+ return(titles.length == 1 ? titles.pop : titles)
+ end
- def to_s
- if title.is_a?(Puppet::Parser::AST::ASTArray)
- "#{type.to_s.capitalize}#{title}"
- else
- "#{type.to_s.capitalize}[#{title}]"
- end
+ def to_s
+ if title.is_a?(Puppet::Parser::AST::ASTArray)
+ "#{type.to_s.capitalize}#{title}"
+ else
+ "#{type.to_s.capitalize}[#{title}]"
end
+ end
end
diff --git a/lib/puppet/parser/ast/resourceparam.rb b/lib/puppet/parser/ast/resourceparam.rb
index bf0a2258b..4073a197b 100644
--- a/lib/puppet/parser/ast/resourceparam.rb
+++ b/lib/puppet/parser/ast/resourceparam.rb
@@ -1,29 +1,29 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # The AST object for the parameters inside ResourceDefs and Selectors.
- class ResourceParam < AST::Branch
- attr_accessor :value, :param, :add
+ # The AST object for the parameters inside ResourceDefs and Selectors.
+ class ResourceParam < AST::Branch
+ attr_accessor :value, :param, :add
- def each
- [@param,@value].each { |child| yield child }
- end
+ def each
+ [@param,@value].each { |child| yield child }
+ end
- # Return the parameter and the value.
- def evaluate(scope)
+ # Return the parameter and the value.
+ def evaluate(scope)
- return Puppet::Parser::Resource::Param.new(
+ return Puppet::Parser::Resource::Param.new(
- :name => @param,
- :value => @value.safeevaluate(scope),
+ :name => @param,
+ :value => @value.safeevaluate(scope),
- :source => scope.source, :line => self.line, :file => self.file,
- :add => self.add
- )
- end
+ :source => scope.source, :line => self.line, :file => self.file,
+ :add => self.add
+ )
+ end
- def to_s
- "#{@param} => #{@value.to_s}"
- end
+ def to_s
+ "#{@param} => #{@value.to_s}"
end
+ end
end
diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb
index cf6b8ac19..d6a4ea436 100644
--- a/lib/puppet/parser/ast/selector.rb
+++ b/lib/puppet/parser/ast/selector.rb
@@ -1,44 +1,44 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # The inline conditional operator. Unlike CaseStatement, which executes
- # code, we just return a value.
- class Selector < AST::Branch
- attr_accessor :param, :values
+ # The inline conditional operator. Unlike CaseStatement, which executes
+ # code, we just return a value.
+ class Selector < AST::Branch
+ attr_accessor :param, :values
- def each
- [@param,@values].each { |child| yield child }
- end
+ def each
+ [@param,@values].each { |child| yield child }
+ end
- # Find the value that corresponds with the test.
- def evaluate(scope)
- level = scope.ephemeral_level
- # Get our parameter.
- paramvalue = @param.safeevaluate(scope)
+ # Find the value that corresponds with the test.
+ def evaluate(scope)
+ level = scope.ephemeral_level
+ # Get our parameter.
+ paramvalue = @param.safeevaluate(scope)
- default = nil
+ default = nil
- @values = [@values] unless @values.instance_of? AST::ASTArray or @values.instance_of? Array
+ @values = [@values] unless @values.instance_of? AST::ASTArray or @values.instance_of? Array
- # Then look for a match in the options.
- @values.each do |obj|
- # short circuit asap if we have a match
- return obj.value.safeevaluate(scope) if obj.param.evaluate_match(paramvalue, scope)
+ # Then look for a match in the options.
+ @values.each do |obj|
+ # short circuit asap if we have a match
+ return obj.value.safeevaluate(scope) if obj.param.evaluate_match(paramvalue, scope)
- # Store the default, in case it's necessary.
- default = obj if obj.param.is_a?(Default)
- end
+ # Store the default, in case it's necessary.
+ default = obj if obj.param.is_a?(Default)
+ end
- # Unless we found something, look for the default.
- return default.value.safeevaluate(scope) if default
+ # Unless we found something, look for the default.
+ return default.value.safeevaluate(scope) if default
- self.fail Puppet::ParseError, "No matching value for selector param '#{paramvalue}'"
- ensure
- scope.unset_ephemeral_var(level)
- end
+ self.fail Puppet::ParseError, "No matching value for selector param '#{paramvalue}'"
+ ensure
+ scope.unset_ephemeral_var(level)
+ end
- def to_s
- param.to_s + " ? { " + values.collect { |v| v.to_s }.join(', ') + " }"
- end
+ def to_s
+ param.to_s + " ? { " + values.collect { |v| v.to_s }.join(', ') + " }"
end
+ end
end
diff --git a/lib/puppet/parser/ast/tag.rb b/lib/puppet/parser/ast/tag.rb
index 2909504a7..6f906a1c6 100644
--- a/lib/puppet/parser/ast/tag.rb
+++ b/lib/puppet/parser/ast/tag.rb
@@ -1,24 +1,24 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # The code associated with a class. This is different from components
- # in that each class is a singleton -- only one will exist for a given
- # node.
- class Tag < AST::Branch
- @name = :class
- attr_accessor :type
+ # The code associated with a class. This is different from components
+ # in that each class is a singleton -- only one will exist for a given
+ # node.
+ class Tag < AST::Branch
+ @name = :class
+ attr_accessor :type
- def evaluate(scope)
- types = @type.safeevaluate(scope)
+ def evaluate(scope)
+ types = @type.safeevaluate(scope)
- types = [types] unless types.is_a? Array
+ types = [types] unless types.is_a? Array
- types.each do |type|
- # Now set our class. We don't have to worry about checking
- # whether we've been evaluated because we're not evaluating
- # any code.
- scope.setclass(self.object_id, type)
- end
- end
+ types.each do |type|
+ # Now set our class. We don't have to worry about checking
+ # whether we've been evaluated because we're not evaluating
+ # any code.
+ scope.setclass(self.object_id, type)
+ end
end
+ end
end
diff --git a/lib/puppet/parser/ast/vardef.rb b/lib/puppet/parser/ast/vardef.rb
index f103d49c3..6de1860c8 100644
--- a/lib/puppet/parser/ast/vardef.rb
+++ b/lib/puppet/parser/ast/vardef.rb
@@ -1,33 +1,33 @@
require 'puppet/parser/ast/branch'
class Puppet::Parser::AST
- # Define a variable. Stores the value in the current scope.
- class VarDef < AST::Branch
+ # Define a variable. Stores the value in the current scope.
+ class VarDef < AST::Branch
- associates_doc
+ associates_doc
- attr_accessor :name, :value, :append
+ attr_accessor :name, :value, :append
- @settor = true
+ @settor = true
- # Look up our name and value, and store them appropriately. The
- # lexer strips off the syntax stuff like '$'.
- def evaluate(scope)
- value = @value.safeevaluate(scope)
- if name.is_a?(HashOrArrayAccess)
- name.assign(scope, value)
- else
- name = @name.safeevaluate(scope)
+ # Look up our name and value, and store them appropriately. The
+ # lexer strips off the syntax stuff like '$'.
+ def evaluate(scope)
+ value = @value.safeevaluate(scope)
+ if name.is_a?(HashOrArrayAccess)
+ name.assign(scope, value)
+ else
+ name = @name.safeevaluate(scope)
- parsewrap do
- scope.setvar(name,value, :file => @file, :line => @line, :append => @append)
- end
- end
+ parsewrap do
+ scope.setvar(name,value, :file => @file, :line => @line, :append => @append)
end
+ end
+ end
- def each
- [@name,@value].each { |child| yield child }
- end
+ def each
+ [@name,@value].each { |child| yield child }
end
+ end
end