Ejemplo n.º 1
0
 /**
  * Parses the given tokens
  *
  * @param array $tokens
  */
 public function parse(&$tokens)
 {
     $startRegexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '/');
     $tagRegexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '\\s*(\\w+)\\s*(.*)?' . LIQUID_TAG_END . '$/');
     $variableStartRegexp = new LiquidRegexp('/^' . LIQUID_VARIABLE_START . '/');
     $this->_nodelist = array();
     if (!is_array($tokens)) {
         return;
     }
     $tags = LiquidTemplate::getTags();
     while (count($tokens)) {
         $token = array_shift($tokens);
         if ($startRegexp->match($token)) {
             if ($tagRegexp->match($token)) {
                 // if we found the proper block delimitor just end parsing here and let the outer block proceed
                 if ($tagRegexp->matches[1] == $this->blockDelimiter()) {
                     return $this->endTag();
                 }
                 if (array_key_exists($tagRegexp->matches[1], $tags)) {
                     $tag_name = $tags[$tagRegexp->matches[1]];
                 } else {
                     $tag_name = 'LiquidTag' . ucwords($tagRegexp->matches[1]);
                     // search for a defined class of the right name, instead of searching in an array
                     $tag_name = Liquid::classExists($tag_name) === true ? $tag_name : null;
                 }
                 if (class_exists($tag_name)) {
                     $this->_nodelist[] = new $tag_name($tagRegexp->matches[2], $tokens, $this->_fileSystem);
                     if ($tagRegexp->matches[1] == 'extends') {
                         return true;
                     }
                 } else {
                     $this->unknownTag($tagRegexp->matches[1], $tagRegexp->matches[2], $tokens);
                 }
             } else {
                 throw new LiquidException("Tag {$token} was not properly terminated");
                 // harry
             }
         } elseif ($variableStartRegexp->match($token)) {
             $this->_nodelist[] = $this->_createVariable($token);
         } elseif ($token != '') {
             $this->_nodelist[] = $token;
         }
     }
     $this->assertMissingDelimitation();
 }
Ejemplo n.º 2
0
 /**
  * Parses the given tokens
  *
  * @param array $tokens
  */
 public function parse(&$tokens)
 {
     $start_regexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '/');
     $tag_regexp = new LiquidRegexp('/^' . LIQUID_TAG_START . '\\s*(\\w+)\\s*(.*)?' . LIQUID_TAG_END . '$/');
     $variable_start_regexp = new LiquidRegexp('/^' . LIQUID_VARIABLE_START . '/');
     new dBug("Start = LiquidBlock::Parse");
     new dBug(func_get_args(), "Arguments = LiquidBlock::Parse");
     $this->_nodelist = array();
     new dBug($this->_nodelist, 'when nodelist intialized');
     if (!is_array($tokens)) {
         return;
     }
     $tags = LiquidTemplate::getTags();
     new dBug($tags, "all tags");
     while (count($tokens)) {
         $token = array_shift($tokens);
         new dBug("token: " . $token);
         new dBug($this->_nodelist, 'in tokens loop: _nodelist');
         if ($start_regexp->match($token)) {
             if ($tag_regexp->match($token)) {
                 new dBug($tag_regexp->matches, "token tag matches");
                 // if we found the proper block delimitor just end parsing here and let the outer block proceed
                 if ($tag_regexp->matches[1] == $this->block_delimiter()) {
                     //new dBug($this->end_tag(), "token tag matches");exit();
                     return $this->end_tag();
                 }
                 if (array_key_exists($tag_regexp->matches[1], $tags)) {
                     $tag_name = $tags[$tag_regexp->matches[1]];
                 } else {
                     $tag_name = 'LiquidTag' . ucwords($tag_regexp->matches[1]);
                 }
                 // search for a defined class of the right name, instead of searching in an array
                 new dBug($tag_name);
                 //exit();
                 // fetch the tag from registered blocks
                 if (class_exists($tag_name)) {
                     new dBug('tag name found: ' . $tag_name);
                     new dBug($this->_nodelist, 'before tag_name call');
                     $temp = new $tag_name($tag_regexp->matches[2], $tokens, $this->file_system);
                     new dBug($temp, 'after tag_name call');
                     exit;
                     //						$this->_nodelist[] = new $tag_name($tag_regexp->matches[2], $tokens, $this->file_system);
                     new dBug($this->_nodelist, 'after tag_name call');
                 } else {
                     new dBug('unknown tag: ' . $tag_name);
                     //exit();
                     $this->unknown_tag($tag_regexp->matches[1], $tag_regexp->matches[2], $tokens);
                 }
             } else {
                 throw new LiquidException("Tag {$token} was not properly terminated");
                 // harry
             }
         } elseif ($variable_start_regexp->match($token)) {
             new dBug($this->_nodelist, 'before create_variable call');
             $this->_nodelist[] = $this->create_variable($token);
             new dBug($this->_nodelist, 'after create_variable call');
         } elseif ($token != '') {
             new dBug($this->_nodelist, 'before blank token assignment');
             $this->_nodelist[] = $token;
             new dBug($this->_nodelist, 'after blank token assignment');
         }
     }
     new dBug('shouldnnot be here');
     $this->assert_missing_delimitation();
 }