コード例 #1
0
ファイル: Evaluator.php プロジェクト: ghooning/peval
 /**
  * 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;
 }
コード例 #2
0
ファイル: FunctionHelper.php プロジェクト: ghooning/peval
 /**
  * This methods takes a string of input function arguments, evaluates each
  * argument and creates a one String and two Integers value for each
  * argument from the result of the evaluations.
  *
  * @param \Tbm\Peval\Types\String $arguments
  * @param $delimiter
  *            The delimiter to use while parsing.
  *
  * @return \Tbm\Peval\Collection\ArrayList An array list of object values found in the input string.
  *
  * @throws \Tbm\Peval\Func\FunctionException
  *                Thrown if the string does not properly parse into the
  *                proper objects.
  */
 public static function getOneStringAndTwoIntegers(string $arguments, $delimiter)
 {
     $returnValues = new ArrayList();
     try {
         $tokenizer = new ArgumentTokenizer($arguments, $delimiter);
         $tokenCtr = 0;
         while ($tokenizer->hasMoreTokens()) {
             if ($tokenCtr == 0) {
                 $token = $tokenizer->nextToken()->trim();
                 $returnValues . add($token);
             } else {
                 if ($tokenCtr == 1 || $tokenCtr == 2) {
                     $token = $tokenizer->nextToken()->trim();
                     $tokenDouble = new Double($token);
                     $tokenInteger = new Integer($tokenDouble->intValue());
                     $returnValues->add($tokenInteger);
                 } else {
                     throw new FunctionException("Invalid values in string.");
                 }
             }
             $tokenCtr++;
         }
     } catch (Exception $e) {
         throw new FunctionException("Invalid values in string.", $e);
     }
     return $returnValues;
 }