コード例 #1
0
 /**
  * Parses function
  *
  * @return XmlImportSpintaxFunction
  */
 private function parseSpintax()
 {
     $spintax = new XmlImportAstSpintax($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 $spintax;
     } else {
         while ($this->index < count($this->tokens) - 2) {
             $spintax->addArgument($this->parseExpression());
             if ($this->tokens[$this->index + 1]->getKind() == XmlImportToken::KIND_CLOSE) {
                 $this->index++;
                 return $spintax;
                 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");
     }
 }
コード例 #2
0
 /**
  * Generates code for a function
  *
  * @param XmlImportAstSpintax $expression
  * @return string
  */
 private function generateForSpintax(XmlImportAstSpintax $spintax)
 {
     $result = '';
     $arguments = $spintax->getArguments();
     $elements = array();
     $buf = array();
     for ($i = 0; $i < count($arguments); $i++) {
         if ($arguments[$i]->getValue() != '|') {
             array_push($buf, $this->generateForExpression($arguments[$i], true));
         } else {
             array_push($elements, $buf);
             $buf = array();
         }
     }
     array_push($elements, $buf);
     if (!empty($elements) and is_array($elements)) {
         $spintax_arr = $this->generateVariation($elements);
         foreach ($spintax_arr as $key => $value) {
             $result .= "\"<p>\"." . implode(".", $value) . ".\"</p>\"";
             if ($key != count($spintax_arr) - 1) {
                 $result .= ".";
             }
         }
     }
     return $result;
 }