Example #1
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();
 }
Example #2
0
 public function addChild(Node $node, $key = null)
 {
     if (!$node instanceof ClassNode) {
         throw new \InvalidArgumentException('FileNode expects only ClassNode children');
     }
     return parent::addChild($node, $key);
 }
Example #3
0
 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;
 }
Example #4
0
 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;
 }