Skip to content

Commit d3e623d

Browse files
committed
Fix "SELECT ... WHERE ... INTO @var" using a negative lookahead
1 parent f9a98aa commit d3e623d

File tree

3 files changed

+11
-315
lines changed

3 files changed

+11
-315
lines changed

custom-parser/parser/DynamicRecursiveDescentParser.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ private function parse_recursive($rule_id) {
422422
$node->append_child($subnode);
423423
}
424424
}
425+
426+
// Negative lookahead for INTO after a valid SELECT statement.
427+
// If we match a SELECT statement, but there is an INTO keyword after it,
428+
// we're in the wrong branch and need to leave matching to a later rule.
429+
// For now, it's hard-coded, but we could extract it to a lookahead table.
430+
$la = $this->tokens[$this->position] ?? null;
431+
if ($la && $rule_name === 'selectStatement' && $la->type === MySQLLexer::INTO_SYMBOL) {
432+
$branch_matches = false;
433+
}
434+
425435
if ($branch_matches === true) {
426436
break;
427437
}

0 commit comments

Comments
 (0)