Example #1
0
 function parse($source, $filename = '', $env = null)
 {
     if (!$env) {
         $env = $this->options;
     }
     if (!class_exists('H2o_Parser')) {
         require H2O_ROOT . 'h2o/parser.php';
     }
     $parser = new H2o_Parser($source, $filename, $this, $env);
     $nodelist = $parser->parse();
     return $nodelist;
 }
Example #2
0
 function __construct($argstring, $parser, $position = 0)
 {
     # get all aliases alias
     if (!empty($argstring)) {
         $arguments = array_map('trim', explode(',', $argstring));
         foreach ($arguments as $argument) {
             if (strpos($argument, '=')) {
                 list($alias, $variable) = explode('=', $argument);
             } else {
                 $variable = $alias = $argument;
             }
             $this->aliases[trim($alias)] = H2o_Parser::parseArguments($variable);
         }
     }
     # Parse singular and plural block
     $this->singular = $parser->parse('plural', 'endblocktrans');
     if ($parser->token->content === 'plural') {
         $this->plural = $parser->parse('endblocktrans');
     }
     # compile nodes into string format
     if ($this->singular) {
         $this->singular = $this->compile_nodes($this->singular);
     }
     if ($this->plural) {
         $this->plural = $this->compile_nodes($this->plural);
     }
 }
Example #3
0
 function __construct($argstring, $parser, $position = 0)
 {
     $this->body = $parser->parse('endif', 'else');
     if ($parser->token->content === 'else') {
         $this->else = $parser->parse('endif');
     }
     $this->args = H2o_Parser::parseArguments($argstring);
     // Remove the 'expression_end' token at the end
     array_pop($this->args);
     $first = current($this->args);
     if (isset($first['operator']) && $first['operator'] === 'not') {
         array_shift($this->args);
         $this->negate = true;
     }
 }
Example #4
0
 function __construct($argstring, $parser, $position = 0)
 {
     if (preg_match('/\\s(and|or)\\s/', $argstring)) {
         throw new TemplateSyntaxError('H2o doesn\'t support multiple expressions');
     }
     $this->body = $parser->parse('endif', 'else');
     if ($parser->token->content === 'else') {
         $this->else = $parser->parse('endif');
     }
     $this->args = H2o_Parser::parseArguments($argstring);
     $first = current($this->args);
     if (isset($first['operator']) && $first['operator'] === 'not') {
         array_shift($this->args);
         $this->negate = true;
     }
 }
Example #5
0
 function &parse()
 {
     $until = func_get_args();
     $nodelist = new NodeList($this);
     while ($token = $this->tokenstream->next()) {
         //$token = $this->tokenstream->current();
         switch ($token->type) {
             case 'text':
                 $node = new TextNode($token->content, $token->position);
                 break;
             case 'variable':
                 $args = H2o_Parser::parseArguments($token->content, $token->position);
                 $variable = array_shift($args);
                 $filters = $args;
                 $node = new VariableNode($variable, $filters, $token->position);
                 break;
             case 'comment':
                 $node = new CommentNode($token->content);
                 break;
             case 'block':
                 if (in_array($token->content, $until)) {
                     $this->token = $token;
                     return $nodelist;
                 }
                 $temp = preg_split('/\\s+/', $token->content, 2);
                 $name = $temp[0];
                 $args = count($temp) > 1 ? $temp[1] : null;
                 $node = H2o::createTag($name, $args, $this, $token->position);
                 $this->token = $token;
         }
         $this->searching = join(',', $until);
         $this->first = false;
         $nodelist->append($node);
     }
     if ($until) {
         throw new TemplateSyntaxError('Unclose tag, expecting ' . $until[0]);
     }
     return $nodelist;
 }
Example #6
0
 private function parse($string)
 {
     return H2o_Parser::parseArguments($string);
 }
Example #7
0
 function __construct($argstring, $parser, $position = 0)
 {
     $this->args = H2o_Parser::parseArguments($argstring);
 }
Example #8
0
 function __construct($argstring, $parser, $pos = 0)
 {
     $this->args = H2o_Parser::parseArguments($argstring);
     $this->args[1] = str_replace("'", "", $this->args[1]);
 }