fix(plsql): reorder grant/revoke alternatives to prioritize object_privilege#46
Merged
Conversation
1. **`grant_statement` (line 2399-2406)**: Reordered the alternatives so `object_privilege` is checked first, then `system_privilege`, then `role_name`. Previously `role_name` was first, which caused keywords like `DELETE` to be incorrectly recognized as role names instead of object privileges. 2. **`revoke_statement` (line 2420-2422)**: Reordered to try `revoke_object_privileges` before `revoke_system_privilege`. This ensures that the more specific rule (with ON clause) is tried first. The parser builds successfully and all tests pass.
There was a problem hiding this comment.
Pull request overview
This PR fixes a parser bug where SQL privilege keywords (like DELETE, SELECT, INSERT, UPDATE) were incorrectly being recognized as role names instead of object privileges in GRANT and REVOKE statements. The fix reorders grammar alternatives to prioritize more specific matches over general identifier matches.
- Reordered
grant_statementalternatives to checkobject_privilegebeforerole_name - Reordered
revoke_statementalternatives to checkrevoke_object_privilegesbeforerevoke_system_privilege
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plsql/PlSqlParser.g4 | Updated grammar rules to prioritize specific privilege keywords over general role name identifiers |
| plsql/plsql_parser.go | Auto-generated parser code reflecting the grammar changes, including reordered interface methods, implementation methods, and state machine transitions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
grant_statementalternatives soobject_privilegeis checked beforerole_namerevoke_statementalternatives sorevoke_object_privilegesis checked beforerevoke_system_privilegeThis fixes an issue where keywords like
DELETE,SELECT, etc. were incorrectly recognized asrole_nameinstead ofobject_privilegebecauserole_name(which matches any identifier viaid_expression) appeared first in the alternatives list.Test plan
make buildmake test🤖 Generated with Claude Code