summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/caseopt.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-13 23:16:26 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-13 23:16:26 +0000
commit87b3bb111f2ea68cbeb875f07e826e4f75ea9eea (patch)
treec03530a415b2f90be6b4c6d5b594f0b8c78a3c0b /lib/puppet/parser/ast/caseopt.rb
parent1d4638a03df6821c16c00db3084f89889f19ac33 (diff)
downloadpuppet-87b3bb111f2ea68cbeb875f07e826e4f75ea9eea.tar.gz
puppet-87b3bb111f2ea68cbeb875f07e826e4f75ea9eea.tar.xz
puppet-87b3bb111f2ea68cbeb875f07e826e4f75ea9eea.zip
Moving ast classes into separate files
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@825 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/parser/ast/caseopt.rb')
-rw-r--r--lib/puppet/parser/ast/caseopt.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb
new file mode 100644
index 000000000..258f5081a
--- /dev/null
+++ b/lib/puppet/parser/ast/caseopt.rb
@@ -0,0 +1,66 @@
+class Puppet::Parser::AST
+ # 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
+
+ def each
+ [@value,@statements].each { |child| yield child }
+ end
+
+ # Are we the default option?
+ def default?
+ if defined? @default
+ return @default
+ end
+
+ if @value.is_a?(AST::ASTArray)
+ @value.each { |subval|
+ if subval.is_a?(AST::Default)
+ @default = true
+ break
+ end
+ }
+ else
+ if @value.is_a?(AST::Default)
+ @default = true
+ end
+ end
+
+ unless defined? @default
+ @default = false
+ end
+
+ return @default
+ end
+
+ # You can specify a list of values; return each in turn.
+ def eachvalue
+ if @value.is_a?(AST::ASTArray)
+ @value.each { |subval|
+ yield subval.value
+ }
+ else
+ yield @value.value
+ end
+ end
+
+ # Evaluate the actual statements; this only gets called if
+ # our option matched.
+ def evaluate(scope)
+ return @statements.safeevaluate(scope.newscope)
+ end
+
+ def tree(indent = 0)
+ rettree = [
+ @value.tree(indent + 1),
+ ((@@indline * indent) + self.typewrap(self.pin)),
+ @statements.tree(indent + 1)
+ ]
+ return rettree.flatten.join("\n")
+ end
+ end
+end