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());
 }
 protected function parseFilter($node)
 {
     $this->stream->expect(TokenTypes::T_FILTER);
     while (true) {
         $nameToken = $this->stream->expect(TokenTypes::T_NAME);
         $name = $nameToken->getValue();
         if ($this->stream->test(TokenTypes::T_OPEN_PARAN)) {
             $arguments = $this->parseArguments();
         } else {
             $arguments = new Node\Expression\Arguments();
         }
         if ($this->stream->nextIf(TokenTypes::T_OPEN_PARAN)) {
             $arguments = $this->parseArguments(false);
         }
         $node = new Node\Expression\Filter($node, $name, $arguments, $nameToken->getLine());
         if (!$this->stream->nextIf(TokenTypes::T_FILTER)) {
             break;
         }
     }
     return $node;
 }
Exemple #3
0
 public function decideIfEnd(TokenStream $stream)
 {
     return $stream->nextIf([TokenTypes::T_SECTION_TYPE], 'endblock');
 }
 /**
  * @param TokenStream $stream
  * @return bool
  */
 public function testEnd(TokenStream $stream)
 {
     return $stream->nextIf([TokenTypes::T_SECTION_TYPE], $this->getSectionEnd());
 }