protected function match($token) { $lookaheadType = $this->lexer->lookahead['type']; if ($lookaheadType !== $token && ($token !== StringLexer::T_TYPE || $lookaheadType <= StringLexer::T_TYPE)) { $this->syntaxError($this->lexer->getLiteral($token)); } $this->lexer->moveNext(); }
public function testScannerTokenizesGeometryValueCorrectly() { $value = 'SRID=4326;LINESTRING(0 0.0, 10.1 -10.025, 20.5 25.9, 50 60)'; $tokens = array(array('value' => 'SRID', 'type' => StringLexer::T_SRID, 'position' => 0), array('value' => '=', 'type' => StringLexer::T_EQUALS, 'position' => 4), array('value' => '4326', 'type' => StringLexer::T_INTEGER, 'position' => 5), array('value' => ';', 'type' => StringLexer::T_SEMICOLON, 'position' => 9), array('value' => 'LINESTRING', 'type' => StringLexer::T_LINESTRING, 'position' => 10), array('value' => '(', 'type' => StringLexer::T_OPEN_PARENTHESIS, 'position' => 20), array('value' => 0, 'type' => StringLexer::T_INTEGER, 'position' => 21), array('value' => 0, 'type' => StringLexer::T_FLOAT, 'position' => 23), array('value' => ',', 'type' => StringLexer::T_COMMA, 'position' => 26), array('value' => 10.1, 'type' => StringLexer::T_FLOAT, 'position' => 28), array('value' => -10.025, 'type' => StringLexer::T_FLOAT, 'position' => 33), array('value' => ',', 'type' => StringLexer::T_COMMA, 'position' => 40), array('value' => 20.5, 'type' => StringLexer::T_FLOAT, 'position' => 42), array('value' => 25.9, 'type' => StringLexer::T_FLOAT, 'position' => 47), array('value' => ',', 'type' => StringLexer::T_COMMA, 'position' => 51), array('value' => 50, 'type' => StringLexer::T_INTEGER, 'position' => 53), array('value' => 60, 'type' => StringLexer::T_INTEGER, 'position' => 56), array('value' => ')', 'type' => StringLexer::T_CLOSE_PARENTHESIS, 'position' => 58)); $lexer = new StringLexer($value); foreach ($tokens as $expected) { $lexer->moveNext(); $actual = $lexer->lookahead; $this->assertEquals($expected, $actual); } $this->assertFalse($lexer->moveNext()); }