Ejemplo n.º 1
0
 /**
  * @param $type
  * @param $value
  *
  * @return bool|Token
  */
 public function nextTokenIf($type, $value = null)
 {
     if ($this->next->test($type, $value)) {
         return $this->next();
     }
     return false;
 }
Ejemplo n.º 2
0
 private function parseToken(Token $token, Stream $stream, RootNode $root)
 {
     $value = $token->getValue();
     switch ($token->getType()) {
         case Token::TEXT:
             $root->addChild(new PrintNode($value));
             break;
         case Token::TAG_START:
             try {
                 $node = $this->environment->getTag($value)->parse($this, $stream);
                 if ($node instanceof Node) {
                     $node->addData('line', $token->getLine());
                     $root->addChild($node);
                 }
             } catch (\OutOfBoundsException $e) {
                 throw new ParseException("Unknown {$value} tag", $token->getLine(), $e);
             }
             break;
         default:
             $type = $token->getTypeString();
             $line = $token->getLine();
             throw new ParseException("Unexpected {$type} ({$value}) token", $line);
     }
     return $stream->next();
 }