Ejemplo n.º 1
0
 public function subparse($test = null)
 {
     $nodes = [];
     while (!$this->stream->isEOF()) {
         $token = $this->stream->getToken();
         $node = null;
         if ($token->test([TokenTypes::T_CODE_BLOCK, TokenTypes::T_EOF])) {
             $this->stream->next();
             continue;
         }
         if ($test && call_user_func($test, $this->stream)) {
             break;
         }
         $found = false;
         foreach ($this->parsers as $parser) {
             if ($parser->canParse($token, $this)) {
                 $found = true;
                 $node = $parser->parse($token, $this);
                 break;
             }
         }
         if (!$found) {
             throw new Exception('Syntax error, invalid syntax \'%s\' (%s) on line %d column %d', $token->getValue(), $token->getTokenName(), $token->getLine(), $token->getColumn());
         }
         if ($node) {
             $nodes[] = $node;
         }
     }
     return new Node($nodes, [], 0);
 }
Ejemplo n.º 2
0
 protected function parsePostfix(Node $node = null)
 {
     while (true) {
         $token = $this->stream->getToken();
         if ($token->test(TokenTypes::T_FILTER)) {
             $node = $this->parseFilter($node);
         } else {
             break;
         }
     }
     return $node;
 }