/**
  * Parses function
  *
  * @return XmlImportAstFunction
  */
 private function parseFunction()
 {
     $function = new XmlImportAstFunction($this->tokens[++$this->index]->getValue());
     if ($this->tokens[$this->index + 1]->getKind() != XmlImportToken::KIND_OPEN) {
         throw new XmlImportException("Open brace expected instead of " . $this->tokens[$this->index + 1]->getKind());
     }
     $this->index++;
     if ($this->tokens[$this->index + 1]->getKind() == XmlImportToken::KIND_CLOSE) {
         $this->index++;
         return $function;
     } else {
         while ($this->index < count($this->tokens) - 2) {
             $function->addArgument($this->parseExpression());
             if ($this->tokens[$this->index + 1]->getKind() == XmlImportToken::KIND_CLOSE) {
                 $this->index++;
                 return $function;
                 break;
             } elseif ($this->tokens[$this->index + 1]->getKind() == XmlImportToken::KIND_COMMA) {
                 $this->index++;
             } else {
                 throw new XmlImportException("Comma or closing brace expected instead of " . $this->tokens[$this->index + 1]->getKind());
             }
         }
         throw new XmlImportException("Unexpected end of {$function->getName()} function argument list");
     }
 }
 /**
  * Generates code for a function
  *
  * @param XmlImportAstFunction $function
  * @return string
  */
 private function generateForFunction(XmlImportAstFunction $function)
 {
     $result = $function->getName() . '(';
     $arguments = $function->getArguments();
     for ($i = 0; $i < count($arguments); $i++) {
         $result .= $this->generateForExpression($arguments[$i], true);
         if ($i < count($arguments) - 1) {
             $result .= ', ';
         }
     }
     $result .= ')';
     return $result;
 }