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/component.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/component.rb')
-rw-r--r-- | lib/puppet/parser/ast/component.rb | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb new file mode 100644 index 000000000..f1e6b9648 --- /dev/null +++ b/lib/puppet/parser/ast/component.rb @@ -0,0 +1,99 @@ +class Puppet::Parser::AST + # Evaluate the stored parse tree for a given component. This will + # receive the arguments passed to the component and also the type and + # name of the component. + class Component < AST::Branch + class << self + attr_accessor :name + end + + # The class name + @name = :component + + attr_accessor :name, :args, :code, :scope + + def evaluate(scope,hash,objtype,objname) + + scope = scope.newscope + + # The type is the component or class name + scope.type = objtype + + # The name is the name the user has chosen or that has + # been dynamically generated. This is almost never used + scope.name = objname + + #if self.is_a?(Node) + # scope.isnodescope + #end + + # Additionally, add a tag for whatever kind of class + # we are + scope.tag(objtype) + + unless objname =~ /-\d+/ # it was generated + scope.tag(objname) + end + #scope.base = self.class.name + + + # define all of the arguments in our local scope + if self.args + + # Verify that all required arguments are either present or + # have been provided with defaults. + # FIXME This should probably also require each parent + # class's arguments... + self.args.each { |arg, default| + unless hash.include?(arg) + if defined? default and ! default.nil? + hash[arg] = default + Puppet.debug "Got default %s for %s in %s" % + [default.inspect, arg.inspect, objname.inspect] + else + error = Puppet::ParseError.new( + "Must pass %s to %s of type %s" % + [arg.inspect,name,objtype] + ) + error.line = self.line + error.file = self.file + error.stack = caller + raise error + end + end + } + end + + # Set each of the provided arguments as variables in the + # component's scope. + hash["name"] = objname + hash.each { |arg,value| + begin + scope.setvar(arg,hash[arg]) + rescue Puppet::ParseError => except + except.line = self.line + except.file = self.file + raise except + rescue Puppet::ParseError => except + except.line = self.line + except.file = self.file + raise except + rescue => except + error = Puppet::ParseError.new(except.message) + error.line = self.line + error.file = self.file + error.stack = caller + raise error + end + } + + # Now just evaluate the code with our new bindings. + self.code.safeevaluate(scope) + + # We return the scope, so that our children can make their scopes + # under ours. This allows them to find our definitions. + return scope + end + end + +end |