summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/minus.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-09-26 22:54:42 +0200
committerBrice Figureau <brice@daysofwonder.com>2008-09-30 17:22:07 +0200
commitcfa230a2d7b0c5e57cc0379785bd2025520f1c35 (patch)
tree046bc7c55a6a1a8ed9b36c5371a3901a89a779c4 /lib/puppet/parser/ast/minus.rb
parent850e0baf0fbe321f14d4b9d913ce7dea39c9aa27 (diff)
downloadpuppet-cfa230a2d7b0c5e57cc0379785bd2025520f1c35.tar.gz
puppet-cfa230a2d7b0c5e57cc0379785bd2025520f1c35.tar.xz
puppet-cfa230a2d7b0c5e57cc0379785bd2025520f1c35.zip
Add arithmetic operators to AST
This changeset adds +,-,/,*,<< and >> computation and AST parse nodes.
Diffstat (limited to 'lib/puppet/parser/ast/minus.rb')
-rw-r--r--lib/puppet/parser/ast/minus.rb23
1 files changed, 23 insertions, 0 deletions
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