示例#1
0
 /**
  * Creates a function from a functional.
  *
  * @param SplFixedArray $functional The functional to process.
  * @return SplFixedArray
  */
 public function _makeFunction(SplFixedArray $functional)
 {
     if (($name = $this->_compiler->isFunction($functional[0])) === null) {
         throw new Opt_ItemNotAllowed_Exception('Function', $functional[0]);
     }
     // Determine the requested argument order.
     if ($name[0] == '#') {
         $pos = strpos($name, '#', 1);
         if ($pos === false) {
             throw new Opt_InvalidArgumentFormat_Exception($name, $token);
         }
         $codes = explode(',', substr($name, 1, $pos - 1));
         $name = substr($name, $pos + 1, strlen($name));
         $newArgs = array();
         $i = 0;
         foreach ($codes as $code) {
             $data = explode(':', $code);
             if (!isset($functional[1][$i])) {
                 if (!isset($data[1])) {
                     throw new Opt_FunctionArgument_Exception($i, $name);
                 }
                 $array = new SplFixedArray(2);
                 $array[0] = $data[1];
                 $array[1] = self::SCALAR_WEIGHT;
                 $newArgs[(int) $data[0] - 1] = $array;
             } else {
                 $newArgs[(int) $data[0] - 1] = $functional[1][$i];
             }
             $i++;
         }
         $functional[1] = $newArgs;
     }
     // Parse the argument list.
     $code = $name . '(';
     $weight = self::FUNCTION_WEIGHT;
     $first = true;
     foreach ($functional[1] as $argument) {
         if (!$first) {
             $code .= ',';
         } else {
             $first = false;
         }
         $code .= $argument[0];
         $weight += $argument[1];
     }
     $obj = new SplFixedArray(4);
     $obj[0] = $code . ')';
     $obj[1] = $weight;
     $obj[3] = 0;
     return $obj;
 }