Repository navigation
fix(parser): report syntax errors at their real position - #190
Merged
Merged
Conversation
Parse errors always said position 0 and showed nom's debug output, because alt/opt/many0 backtrack and drop the inner errors. Record the furthest point any parser reached and what it expected there, and report line, column, the expected tokens and what was found. Fixes #184
Deploying lance-csr with
|
| Latest commit: |
32ad157
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e047051a.lance-csr.pages.dev |
| Branch Preview URL: | https://fix-cypher-syntax-error-posi.lance-csr.pages.dev |
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.
Why
Every Cypher syntax error was reported at position 0, with nom's internal debug output as the message. nom's
alt,optandmany0backtrack and throw away the inner errors, so the error that reached the top almost always pointed at the start of the query and said nothing about what was wrong.Fixes #184.
What changed
Before:
After:
tag,tag_no_caseandcharparsers are wrapped to record what they expected, and a failed name reads as "a name". The error reports that point as a line and column, the expected tokens, and what it found instead.SKIP/LIMIT, an out-of-range integer or float literal, andDISTINCTon a non-aggregate function.GraphError::ParseErrorgainslineandcolumnfields.positionis now the real byte offset. The display text changes from "Cypher parse error at position N" to "Cypher syntax error at line L, column C". Nothing in the repository matched on the old text.UnsupportedFeaturefirst, as added in fix(parser): reject write clauses as unsupported features #189.Known limit: the furthest failure is a heuristic. Because keywords are accepted as variable names,
WHERE n.age >followed byRETURN nparsesRETURNas the right-hand side and reports the error at thenafter it.Validation
cargo test --workspace: all suites pass, including a new parser test covering the cases above.cargo clippy --workspace --all-targets -- -D warnings: clean.zensical build --strictandtypos@1.52.0: clean.🤖 Generated with Claude Code