/** * @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); } }
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); } } }
/** * 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']; }