Exemplo n.º 1
0
 /** @dataProvider getParserFixtures */
 public function testParser($file)
 {
     $parts = $this->parseTestFile($file);
     try {
         $parser = new Parser();
         $node = $parser->parse($parts['HAML'], $file, 2);
         $renderer = new Printer();
         $node->accept($renderer);
     } catch (\Exception $e) {
         return $this->assertException($parts, $e);
     }
     $this->assertException($parts);
     file_put_contents($file . '.out', $renderer->getOutput());
     $this->assertSame($parts['EXPECT'], $renderer->getOutput());
     unlink($file . '.out');
 }
Exemplo n.º 2
0
 protected function parseStatement($buf)
 {
     if (empty($this->currentMoreEnv)) {
         return parent::parseStatement($buf);
     }
     if (null !== ($node = $this->parseSnipCaller($buf))) {
         return $node;
     } else {
         if (null !== ($node = $this->parsePlaceholderValue($buf))) {
             return $node;
         } else {
             if (null !== ($node = $this->parsePlaceholder($buf))) {
                 return $node;
             } else {
                 if (null !== ($node = $this->parseHtmlTag($buf))) {
                     return $node;
                 } else {
                     if (null !== ($node = $this->parsePlaceholderDefaultValueCaller($buf))) {
                         return $node;
                     } else {
                         return parent::parseStatement($buf);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 protected function parseTag($buf)
 {
     $arr = (array) $this->env->getOption('shortcut');
     //		if ( empty( $arr ) ) {
     //			return parent::parseTag( $buf );
     //		}
     $shortcuts = array();
     $prefixes[] = '\\%';
     foreach ($arr as $s => $p) {
         if (!empty($p['tag'])) {
             $prefixes[] = '\\' . $s;
             $shortcuts[$s] = $p;
         }
     }
     //inject @include and @require
     $shortcuts['@'][] = 'include';
     $shortcuts['@'][] = 'require';
     $prefixes[] = '\\@';
     $prefixes = implode('|', array_unique($prefixes));
     //        Dbg::emsgd($prefixes); return;
     $tagRegex = '/
         (?P<shortcut>' . $prefixes . ')(?P<tag_name>[\\w:-]+)  # explicit tag name ( %tagname )
         | (?=[.#][\\w-])         # implicit div followed by class or id
                                 # ( .class or #id )
         /xA';
     //Dbg::emsgd($tagRegex); return;
     if ($buf->match($tagRegex, $match)) {
         $new_type = null;
         $tag_name = empty($match['tag_name']) ? 'div' : $match['tag_name'];
         if (!empty($shortcuts[$match['shortcut']])) {
             //@include adn @require
             if ('@' === $match['shortcut'] && ('require' === $match['tag_name'] || 'include' === $match['tag_name'])) {
                 return $this->injectFile($buf, $match['tag_name']);
             }
             $params = $shortcuts[$match['shortcut']];
             $tag_name = $params['tag'];
             //Dbg::emsgd($params['tag']);
             $name = new Text($match['pos'][0], $params['attr']);
             $value = new Text($match['pos'][1], $match['tag_name']);
             $new_type = new TagAttribute($match['pos'][0], $name, $value);
         }
         $attributes = $this->parseTagAttributesShortcut($buf);
         $flags = $this->parseTagFlags($buf);
         $node = new Tag($match['pos'][0], $tag_name, $attributes, $flags);
         if ($new_type !== null) {
             $node->addAttribute($new_type);
         }
         $buf->skipWs();
         if (null !== ($nested = $this->parseNestableStatement($buf))) {
             if ($flags & Tag::FLAG_SELF_CLOSE) {
                 $msg = 'Illegal nesting: nesting within a self-closing tag is illegal';
                 $this->syntaxError($buf, $msg);
             }
             $node->setContent($nested);
         }
         return $node;
     } else {
         return parent::parseTag($buf);
     }
 }