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;
 }
Ejemplo n.º 3
0
 public function testTokenStream()
 {
     $stream = new TokenStream([new Token(null, 'Hello', TokenTypes::T_NAME, 0, 0), new Token(null, '"World"', TokenTypes::T_STR, 0, 0), new Token(null, '', TokenTypes::T_EOF, 0, 0)]);
     $this->assertTrue($stream->test(TokenTypes::T_NAME, 'Hello'));
     $this->assertEquals(new Token(null, '"World"', TokenTypes::T_STR, 0, 0), $stream->nextIf(TokenTypes::T_STR));
     $this->assertEquals(new Token(null, '"World"', TokenTypes::T_STR, 0, 0), $stream->getCurrent());
     $this->assertEquals(new Token(null, '"World"', TokenTypes::T_STR, 0, 0), $stream->expect(TokenTypes::T_STR));
     $this->assertTrue($stream->isEOF());
 }
Ejemplo n.º 4
0
 public function decideIfBraceEnd(TokenStream $stream)
 {
     return $stream->test([TokenTypes::T_SECTION_CLOSE], '}');
 }
Ejemplo n.º 5
0
 public function testEndBrace(TokenStream $stream)
 {
     return $stream->test(TokenTypes::T_SECTION_CLOSE, '}');
 }