Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert token index in AbstractLexer. #18

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/Doctrine/Common/Lexer/AbstractLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ abstract class AbstractLexer
* Array of scanned tokens.
*
* Each token is an associative array containing three items:
* - 'index' : the token index in the input string
* - 'value' : the string value of the token in the input string
* - 'type' : the type of the token (identifier, numeric, string, input
* parameter, none)
Expand Down Expand Up @@ -133,7 +132,7 @@ public function resetPosition($position = 0)
}

/**
* Retrieve the original lexer's input until a given position.
* Retrieve the original lexer's input until a given position.
*
* @param integer $position
*
Expand Down Expand Up @@ -259,18 +258,15 @@ protected function scan($input)
$flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
$matches = preg_split($regex, $input, -1, $flags);

$index = 0;
foreach ($matches as $match) {
// Must remain before 'value' assignment since it can change content
$type = $this->getType($match[0]);

$this->tokens[$index] = array(
'index' => $index,
$this->tokens[] = array(
'value' => $match[0],
'type' => $type,
'position' => $match[1],
);
$index++;
}
}

Expand Down
10 changes: 0 additions & 10 deletions tests/Doctrine/Common/Lexer/AbstractLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ public function dataProvider()
'price=10',
array(
array(
'index' => 0,
'value' => 'price',
'type' => 'string',
'position' => 0,
),
array(
'index' => 1,
'value' => '=',
'type' => 'operator',
'position' => 5,
),
array(
'index' => 2,
'value' => 10,
'type' => 'int',
'position' => 6,
Expand All @@ -47,19 +44,16 @@ public function testResetPeek()
{
$expectedTokens = array(
array(
'index' => 0,
'value' => 'price',
'type' => 'string',
'position' => 0,
),
array(
'index' => 1,
'value' => '=',
'type' => 'operator',
'position' => 5,
),
array(
'index' => 2,
'value' => 10,
'type' => 'int',
'position' => 6,
Expand All @@ -78,19 +72,16 @@ public function testResetPosition()
{
$expectedTokens = array(
array(
'index' => 0,
'value' => 'price',
'type' => 'string',
'position' => 0,
),
array(
'index' => 1,
'value' => '=',
'type' => 'operator',
'position' => 5,
),
array(
'index' => 2,
'value' => 10,
'type' => 'int',
'position' => 6,
Expand Down Expand Up @@ -142,7 +133,6 @@ public function testSkipUntil()

$this->assertEquals(
array(
'index' => 1,
'value' => '=',
'type' => 'operator',
'position' => 5,
Expand Down