Пример #1
0
 /**
  * Parse the next token
  *
  * @return void
  */
 protected function next()
 {
     $token = $this->currentToken();
     // we can skip linebreaks
     if ($token->type === 'linebreak') {
         $this->skipToken();
     } elseif ($token->type === 'identifier') {
         $this->scope->addChild($this->parseChild('ShortTag'));
     } elseif ($token->type === 'tagOpen') {
         $this->scope->addChild($this->parseChild('Tag'));
     } elseif (in_array($token->type, array('foreach', 'loop'))) {
         $loopTokens = $this->getRemainingTokens();
         if ($token->type === 'foreach') {
             $loopParser = new Loop\Each($loopTokens);
         }
         $loopNode = $loopParser->parse();
         $this->scope->addChild($loopNode);
         $scopeNode = $this->scope;
         $loopNode->onReciveContext(function ($context) use($scopeNode, $loopNode) {
             // because the loop itself has no real context
             // we have to forward the context of the current scope
             $loopNode->setChildContext($context);
         });
         $this->skipToken($loopParser->getIndex());
     } elseif ($token->type === 'variable') {
         $this->scope->addChild($this->parseChild('VarDeclaration'));
     } else {
         throw $this->errorUnexpectedToken($token);
     }
 }
Пример #2
0
 /**
  * tests Parser
  */
 public function testBasic()
 {
     $node = new Scope();
     $tag = new Tag();
     $tag->setName('button');
     $node->addChild($tag);
     $node = $this->compile($node);
     $this->assertContains("if (!isset(\$__tattoo_vars)) {", $node);
     $this->assertContains("\$__tattoo_vars = array();", $node);
 }