Skip to content

Commit

Permalink
Fix "SELECT ... WHERE ... INTO @var" using a negative lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJakes committed Sep 26, 2024
1 parent f9a98aa commit d3e623d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 315 deletions.
10 changes: 10 additions & 0 deletions custom-parser/parser/DynamicRecursiveDescentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ private function parse_recursive($rule_id) {
$node->append_child($subnode);
}
}

// Negative lookahead for INTO after a valid SELECT statement.
// If we match a SELECT statement, but there is an INTO keyword after it,
// we're in the wrong branch and need to leave matching to a later rule.
// For now, it's hard-coded, but we could extract it to a lookahead table.
$la = $this->tokens[$this->position] ?? null;
if ($la && $rule_name === 'selectStatement' && $la->type === MySQLLexer::INTO_SYMBOL) {
$branch_matches = false;
}

if ($branch_matches === true) {
break;
}
Expand Down
Loading

0 comments on commit d3e623d

Please sign in to comment.