Esempio n. 1
0
 public function testTokenRecognitionReuseLexer()
 {
     $lexer = new Lexer();
     foreach ($this->tokenData() as $name => $testData) {
         $lexer->setInput($testData['value']);
         foreach ($testData['expected'] as $token) {
             $lexer->moveNext();
             $actual = $lexer->lookahead;
             $this->assertEquals($token[0], $actual['type']);
             $this->assertEquals($token[1], $actual['value']);
             $this->assertEquals($token[2], $actual['position']);
         }
     }
 }
Esempio n. 2
0
 /**
  * Match token at current position in input
  *
  * @param $token
  */
 protected function match($token)
 {
     $lookaheadType = $this->lexer->lookahead['type'];
     if ($lookaheadType !== $token && ($token !== Lexer::T_TYPE || $lookaheadType <= Lexer::T_TYPE)) {
         throw $this->syntaxError($this->lexer->getLiteral($token));
     }
     $this->lexer->moveNext();
 }