Exemple #1
0
 /**
  * Unloads the functions in this function group from an instance of
  * Evaluator.
  * 
  * @param \Tbm\Peval\Evaluator $evaluator
  *            An instance of Evaluator to unload the functions from.
  */
 public function unload(Evaluator $evaluator)
 {
     $functionIterator = $this->functions->iterator();
     while ($functionIterator->valid()) {
         $function = $functionIterator->current();
         $evaluator->removeFunction($function);
         $functionIterator->next();
     }
 }
Exemple #2
0
 /**
  * This method process nested function calls that may be in the arguments
  * passed into a higher level function.
  *
  * @param String|\Tbm\Peval\Types\String $arguments
  *
  * @throws \Tbm\Peval\EvaluationException
  * @return \Tbm\Peval\Types\String The arguments with any nested function calls evaluated.
  *
  */
 public function processNestedFunctions(string $arguments)
 {
     $evaluatedArguments = new String();
     // Process nested function calls.
     if ($arguments->length() > 0) {
         $argumentsEvaluator = new Evaluator($this->quoteCharacter, $this->loadMathVariables, $this->loadMathFunctions, $this->loadStringFunctions, $this->processNestedFunctions);
         $this->argumentsEvaluator->setFunctions(getFunctions());
         $this->argumentsEvaluator->setVariables(getVariables());
         $this->argumentsEvaluator->setVariableResolver(getVariableResolver());
         $tokenizer = new ArgumentTokenizer($arguments, EvaluationConstants::FUNCTION_ARGUMENT_SEPARATOR);
         $evaluatedArgumentList = new ArrayList();
         while ($tokenizer . hasMoreTokens()) {
             $argument = $tokenizer->nextToken()->trim();
             try {
                 $argument = $argumentsEvaluator->evaluate1($argument);
             } catch (Exception $e) {
                 throw new EvaluationException($e->getMessage(), $e);
             }
             $evaluatedArgumentList->add($argument);
         }
         $evaluatedArgumentIterator = $evaluatedArgumentList->iterator();
         while ($evaluatedArgumentIterator->valid()) {
             if ($evaluatedArguments->length() > 0) {
                 $evaluatedArguments->append(EvaluationConstants::FUNCTION_ARGUMENT_SEPARATOR);
             }
             $evaluatedArgumentIterator->next();
             $evaluatedArgument = (string) $evaluatedArgumentIterator->current();
             $evaluatedArguments . append($evaluatedArgument);
         }
     }
     return $evaluatedArguments;
 }