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 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 leaveNode(Node $node)
 {
     if ($this->isBlockRoot($node)) {
         $this->currentBlock->addData('environment_accessed', $this->environmentAccessed);
         unset($this->currentBlock);
     } elseif ($node instanceof ClassNode) {
         unset($this->currentClassNode);
     }
     return true;
 }
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;
 }
Example #5
0
 public function compile(Compiler $compiler)
 {
     $compiler->add("<?php\n");
     /** @var $childNode ClassNode */
     $childNode = $this->getChild(0);
     if ($childNode->getNameSpace() !== '') {
         $compiler->indented("namespace %s;\n", $childNode->getNameSpace());
     }
     $compiler->indented('use Minty\\Environment;');
     $compiler->indented('use Minty\\Context;');
     $compiler->add("\n");
     parent::compile($compiler);
 }
Example #6
0
 private function compileBlock(Compiler $compiler, $method, RootNode $body)
 {
     $compiler->indented('public function %s(Context $context)', $method);
     $compiler->indented('{');
     $compiler->indent();
     if (!$body->hasData('environment_accessed') || $body->getData('environment_accessed')) {
         $compiler->indented('$environment = $this->getEnvironment();');
     }
     $compiler->compileNode($body);
     $compiler->outdent();
     $compiler->indented("}\n");
 }