diff options
Diffstat (limited to 'lib/puppet/parser/ast/function.rb')
-rw-r--r-- | lib/puppet/parser/ast/function.rb | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb index 6f6c869f5..602016c75 100644 --- a/lib/puppet/parser/ast/function.rb +++ b/lib/puppet/parser/ast/function.rb @@ -1,51 +1,51 @@ require 'puppet/parser/ast/branch' class Puppet::Parser::AST - # An AST object to call a function. - class Function < AST::Branch + # An AST object to call a function. + class Function < AST::Branch - associates_doc + associates_doc - attr_accessor :name, :arguments + attr_accessor :name, :arguments - @settor = true + @settor = true - def evaluate(scope) + def evaluate(scope) - # Make sure it's a defined function - raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name) + # Make sure it's a defined function + raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name) - # Now check that it's been used correctly - case @ftype - when :rvalue - raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name) - when :statement - if Puppet::Parser::Functions.rvalue?(@name) - raise Puppet::ParseError, - "Function '#{@name}' must be the value of a statement" - end - else - raise Puppet::DevError, "Invalid function type #{@ftype.inspect}" - end + # Now check that it's been used correctly + case @ftype + when :rvalue + raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name) + when :statement + if Puppet::Parser::Functions.rvalue?(@name) + raise Puppet::ParseError, + "Function '#{@name}' must be the value of a statement" + end + else + raise Puppet::DevError, "Invalid function type #{@ftype.inspect}" + end - # We don't need to evaluate the name, because it's plaintext - args = @arguments.safeevaluate(scope) + # We don't need to evaluate the name, because it's plaintext + args = @arguments.safeevaluate(scope) - scope.send("function_#{@name}", args) - end + scope.send("function_#{@name}", args) + end - def initialize(hash) - @ftype = hash[:ftype] || :rvalue - hash.delete(:ftype) if hash.include? :ftype + def initialize(hash) + @ftype = hash[:ftype] || :rvalue + hash.delete(:ftype) if hash.include? :ftype - super(hash) + super(hash) - # Lastly, check the parity - end + # Lastly, check the parity + end - def to_s - args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments - "#{name}(#{args})" - end + def to_s + args = arguments.is_a?(ASTArray) ? arguments.to_s.gsub(/\[(.*)\]/,'\1') : arguments + "#{name}(#{args})" end + end end |