summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/leaf.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/leaf.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/leaf.rb')
-rw-r--r--lib/puppet/parser/ast/leaf.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
new file mode 100644
index 000000000..53cefdeb3
--- /dev/null
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -0,0 +1,89 @@
+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)
+ return @value
+ end
+
+ # Print the value in parse tree context.
+ def tree(indent = 0)
+ return ((@@indent * indent) + self.typewrap(self.value))
+ end
+
+ def to_s
+ return @value
+ end
+ end
+
+ # The boolean class. True or false. Converts the string it receives
+ # to a Ruby boolean.
+ class Boolean < AST::Leaf
+
+ # Use the parent method, but then convert to a real boolean.
+ def initialize(hash)
+ super
+
+ unless @value == 'true' or @value == 'false'
+ error = Puppet::DevError.new(
+ "'%s' is not a boolean" % @value
+ )
+ error.stack = caller
+ raise error
+ end
+ if @value == 'true'
+ @value = true
+ else
+ @value = false
+ end
+ end
+ end
+
+ # The base string class.
+ class String < AST::Leaf
+ # Interpolate the string looking for variables, and then return
+ # the result.
+ def evaluate(scope)
+ return scope.strinterp(@value)
+ end
+ end
+ #---------------------------------------------------------------
+
+ # The 'default' option on case statements and selectors.
+ class Default < 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
+
+ # Lower-case words.
+ class Name < AST::Leaf; 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)
+ begin
+ return scope.lookupvar(@value)
+ rescue Puppet::ParseError => except
+ except.line = self.line
+ except.file = self.file
+ raise except
+ rescue => detail
+ error = Puppet::DevError.new(detail)
+ error.line = self.line
+ error.file = self.file
+ error.stack = caller
+ raise error
+ end
+ end
+ end
+
+end