Esempio n. 1
0
 /**
  * @param string $input
  * @param array  $tokens
  *
  * @dataProvider testDataSource
  */
 public function testLexer($input, array $tokens)
 {
     $lexer = new Lexer($input);
     $index = 0;
     while (null !== ($actual = $lexer->peek())) {
         $this->assertEquals($tokens[$index++], $actual);
     }
 }
Esempio n. 2
0
 public function testReusedLexer()
 {
     $lexer = new Lexer();
     foreach ($this->testDataSource() as $data) {
         $input = $data['input'];
         $expectedTokens = $data['expectedTokens'];
         $index = 0;
         $lexer->setInput($input);
         while (null !== ($actual = $lexer->peek())) {
             $this->assertEquals($expectedTokens[$index++], $actual);
         }
     }
 }
Esempio n. 3
0
 /**
  * Match token and return value
  *
  * @param int $token
  *
  * @return mixed
  * @throws UnexpectedValueException
  */
 private function match($token)
 {
     // If next token isn't type specified throw error
     if (!$this->lexer->isNextToken($token)) {
         throw $this->syntaxError($this->lexer->getLiteral($token));
     }
     // Move lexer to next token
     $this->lexer->moveNext();
     // Return the token value
     return $this->lexer->token['value'];
 }