diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-13 23:16:26 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-01-13 23:16:26 +0000 |
| commit | 87b3bb111f2ea68cbeb875f07e826e4f75ea9eea (patch) | |
| tree | c03530a415b2f90be6b4c6d5b594f0b8c78a3c0b /lib/puppet/parser/ast/branch.rb | |
| parent | 1d4638a03df6821c16c00db3084f89889f19ac33 (diff) | |
| download | puppet-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/branch.rb')
| -rw-r--r-- | lib/puppet/parser/ast/branch.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/branch.rb b/lib/puppet/parser/ast/branch.rb new file mode 100644 index 000000000..deb8dbadd --- /dev/null +++ b/lib/puppet/parser/ast/branch.rb @@ -0,0 +1,47 @@ +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 + + # 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) + + # Create the hash, if it was not set at initialization time. + unless defined? @children + @children = [] + end + + # Verify that we only got valid AST nodes. + @children.each { |child| + unless child.is_a?(AST) + raise Puppet::DevError, + "child %s is not an ast" % child + end + } + end + + # Pretty-print the parse tree. + def tree(indent = 0) + return ((@@indline * indent) + + self.typewrap(self.pin)) + "\n" + self.collect { |child| + child.tree(indent + 1) + }.join("\n") + end + end +end |
