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(); }
public function addChild(Node $node, $key = null) { if (!$node instanceof ClassNode) { throw new \InvalidArgumentException('FileNode expects only ClassNode children'); } return parent::addChild($node, $key); }
public function parse(Parser $parser, Stream $stream) { $node = new RootNode(); do { $node->addChild(new ExpressionNode($parser->parseExpression($stream))); } while ($stream->current()->test(Token::PUNCTUATION, ',')); return $node; }
public function parse(Parser $parser, Stream $stream) { $node = new RootNode(); do { $left = $parser->parseExpression($stream); $stream->expectCurrent(Token::PUNCTUATION, ':'); $right = $parser->parseExpression($stream); $setOperator = $parser->getEnvironment()->getBinaryOperators()->getOperator(':'); $varNode = $setOperator->createNode($left, $right); $node->addChild(new ExpressionNode($varNode)); } while ($stream->current()->test(Token::PUNCTUATION, ',')); return $node; }