Skip to content

Commit 15a2398

Browse files
committed
Increasing the idx of the tokens instead of using getNext to skip current token
Signed-off-by: iifawzi <[email protected]>
1 parent a70dec0 commit 15a2398

3 files changed

Lines changed: 6 additions & 20 deletions

File tree

src/Components/AlterOperation.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
349349
}
350350
} elseif (! self::checkIfTokenQuotedSymbol($token)) {
351351
if (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
352-
// We want to get the next non-comment and non-space token after $token
353-
// therefore, the first getNext call will start with the current $idx which's $token,
354-
// will return it and increase $idx by 1, which's not guaranteed to be non-comment
355-
// and non-space, that's why we're calling getNext again.
356-
357-
$list->getNext();
352+
$list->idx++; // Ignore the current token
358353
$nextToken = $list->getNext();
359354

360355
if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') {
@@ -387,12 +382,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
387382
$ret->unknown[] = $token;
388383
} elseif ($state === 3) {
389384
if ($partitionState === 0) {
390-
// We want to get the next non-comment and non-space token after $token
391-
// therefore, the first getNext call will start with the current $idx which's $token,
392-
// will return it and increase $idx by 1, which's not guaranteed to be non-comment
393-
// and non-space, that's why we're calling getNext again.
394-
395-
$list->getNext();
385+
$list->idx++; // Ignore the current token
396386
$nextToken = $list->getNext();
397387
if (
398388
($token->type === Token::TYPE_KEYWORD)

src/Statements/ExplainStatement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ public function parse(Parser $parser, TokensList $list)
134134
$state = 2;
135135
} elseif ($state === 2) {
136136
$currIdx = $list->idx;
137-
$currToken = $list->getNext();
137+
$list->idx++; // Ignore the current token
138138
$nextToken = $list->getNext();
139139
$list->idx = $currIdx;
140140

141141
if ($token->keyword === 'FOR' && $nextToken->keyword === 'CONNECTION') {
142-
$forToken = $list->getNext(); // FOR
143-
$connectionToken = $list->getNext(); // CONNECTION
142+
$list->idx++; // Ignore the current token
143+
$list->getNext(); // CONNECTION
144144
$nextToken = $list->getNext(); // Identifier
145145
$this->connectionId = $nextToken->value;
146146
break;

src/Statements/WithStatement.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ public function parse(Parser $parser, TokensList $list)
142142
} elseif ($state === 3) {
143143
$idxBeforeGetNext = $list->idx;
144144

145-
// We want to get the next non-comment and non-space token after $token
146-
// therefore, the first getNext call will start with the current $idx which's $token,
147-
// will return it and increase $idx by 1, which's not guaranteed to be non-comment
148-
// and non-space, that's why we're calling getNext again.
149-
$list->getNext();
145+
$list->idx++; // Ignore the current token
150146
$nextKeyword = $list->getNext();
151147

152148
if (! ($token->value === '(' && ($nextKeyword && $nextKeyword->value === 'SELECT'))) {

0 commit comments

Comments
 (0)