/** * @param $type * @param $value * * @return bool|Token */ public function nextTokenIf($type, $value = null) { if ($this->next->test($type, $value)) { return $this->next(); } return false; }
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(); }