diff options
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r-- | lib/puppet/parser/ast/astarray.rb | 21 | ||||
-rw-r--r-- | lib/puppet/parser/ast/function.rb | 51 |
2 files changed, 66 insertions, 6 deletions
diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb index 356258a96..f8f88b816 100644 --- a/lib/puppet/parser/ast/astarray.rb +++ b/lib/puppet/parser/ast/astarray.rb @@ -22,20 +22,29 @@ class Puppet::Parser::AST # do we need to evaluate the settor-like statements first. This # is basically variable and type-default declarations. if scope.declarative? - test = [ - AST::VarDef, AST::TypeDefaults + # This is such a stupid hack. I've no real idea how to make a + # "real" declarative language, so I hack it so it looks like + # one, yay. + definelist = [ + AST::CompDef, AST::NodeDef, AST::ClassDef + ] + setlist = [ + AST::VarDef, AST::TypeDefaults, AST::Function ] + definers = [] settors = [] others = [] @children.each { |child| - if test.include?(child.class) - settors.push child + if definelist.include?(child.class) + definers << child + elsif setlist.include?(child.class) + settors << child else - others.push child + others << child end } - rets = [settors,others].flatten.collect { |child| + rets = [definers, settors, others].flatten.collect { |child| child.safeevaluate(:scope => scope) } else diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb new file mode 100644 index 000000000..80cc5f09e --- /dev/null +++ b/lib/puppet/parser/ast/function.rb @@ -0,0 +1,51 @@ +class Puppet::Parser::AST + # The code associated with a class. This is different from components + # in that each class is a singleton -- only one will exist for a given + # node. + class Function < AST::Branch + attr_accessor :name, :arguments + + def evaluate(hash) + # We don't need to evaluate the name, because it's plaintext + + # Just evaluate the arguments + scope = hash[:scope] + + args = @arguments.safeevaluate(:scope => scope) + + return scope.send("function_" + @name, args) + end + + def initialize(hash) + @ftype = hash[:ftype] || :rvalue + hash.delete(:ftype) if hash.include? :ftype + + super(hash) + + # Make sure it's a defined function + unless @fname = Puppet::Parser::Functions.function(@name) + raise Puppet::ParseError, "Unknown function %s" % @name + end + + # Now check that it's been used correctly + case @ftype + when :rvalue: + unless Puppet::Parser::Functions.rvalue?(@name) + raise Puppet::ParseError, "Function '%s' does not return a value" % + @name + end + when :statement: + if Puppet::Parser::Functions.rvalue?(@name) + raise Puppet::ParseError, "Function '%s' must be the value of a statement" % + @name + end + else + raise Puppet::DevError, "Invalid function type %s" % @ftype.inspect + end + + # Lastly, check the arity + end + end +end + +# $Id$ |