Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Randomized shared-blank-node diagnostics can cause the prefix check to falsely blame ex: inside a string, requiring preservation of positionless parser errors and regression coverage.
1 open issue
What changed in this PR
This PR adds parser-backed validation before naming an undeclared SPARQL prefix, addressing the false-prefix diagnostics left by #26.
Changes:
- Reparse failed queries and updates with the candidate prefix declared before replacing the parser’s error.
- Add regression tests for false candidates inside strings and comments, and prefixes followed by another error.
- Document the fallback behavior and clarify the scanner’s role.
| File | Description |
|---|---|
test/test_query.rb |
Adds regression coverage for prefix diagnostics. |
README.md |
Explains when the parser’s original message is retained. |
ext/oxigraph/src/query.rs |
Adds shared parser-backed candidate validation for queries and updates. |
ext/oxigraph/src/prefix.rs |
Clarifies in comments that scanned names require parser validation. |
ext/oxigraph/src/error.rs |
Formats errors using the validated candidate instead of a position comparison. |
Review effort: Balanced
The scan that finds an undeclared prefix reads characters and does not parse. A comparison written without spaces, such as ?a<'x>, reads to it as an IRI, and it then takes the rest of the string or comment for query text. The error named a prefix that the query never used. The text is now parsed a second time with the candidate prefix declared. The prefix is named when the parser then accepts the text or refuses it differently. A name the parser never read as a prefix changes nothing, and the parser's own message stays. The second parse runs only for text the parser has already refused. That check replaces the comparison of the name's position with the position in the parser's message. A prefix that another syntax error follows within a few characters may no longer be named, because declaring it can leave the parser's message as it was. The README says so. An error the parser reports without a position is left alone. The parser reports one only for text whose syntax it accepted, so no prefix is behind it. It also names whichever of several shared blank nodes a randomly ordered set yields first, so two parses of one text could word the error differently and confirm a prefix that the text never used.
nertzy
force-pushed
the
prefix-blame-check
branch
from
November 17, 2026 20:42
635e416 to
5d6e1f3
Compare
Owner
Author
|
Superseded by #28, which removes the prefix scan instead of adding a second parse to check it. |
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.

The error for an undeclared prefix could name a prefix the query never used. This checks the name against the parser before blaming it, which closes the known limit left by #26.
The problem
The scan that finds an undeclared prefix reads characters and does not parse. A comparison written without spaces, such as
?a<'x>, reads to it as an IRI. It then takes the rest of the string or comment for query text:FILTER(?a<'x>ex:p'), then an unrelated syntax errorex:, from inside the stringFILTER(?a<?b)#a>b ex:p, then an unrelated syntax errorex:, from inside the commentThe chosen behavior
When the parser refuses a text and the scan finds a candidate prefix, the text is parsed a second time with that prefix declared. The prefix is named when the parser then accepts the text or refuses it differently. A name the parser never read as a prefix changes nothing, so the parser's own message stays.
The second parse runs only on text the parser has already refused. On a 227 KB query with the undeclared prefix on its last line, the failing call took about 26 ms on one machine. A successful parse of the same query took about 20 ms.
An error the parser reports without a position is never checked. The parser reports one only for text whose syntax it accepted, so no prefix is behind it. It also names whichever of several shared blank nodes a randomly ordered set yields first, so two parses of the same text can word that error differently. Before this guard, an update with two shared blank nodes and
FILTER(?a<'x>ex:p')namedex:in 97 of 200 parses.This check replaces the comparison between the name's position and the position in the parser's message, which it makes redundant.
One trade-off
A prefix is no longer named when declaring it leaves the parser's message exactly as it was. That happens when a second syntax error follows the prefix within a few characters, because the parser reports both errors at the same place with the same words.
Of 18 texts I tried that have an undeclared prefix and a second error, 16 still name the prefix. The two that do not are
{ ?s ex:p}and{ ex:a }. Their message is now the parser's, which is vaguer and not wrong. The README says so.Known limits
FILTER(?a<'x>ex:p') . ?s ex:q ?othe query does useex:undeclared, so it is named, but the position points at the copy inside the string.Both need the unspaced comparison followed by a string or comment that holds something shaped like a prefixed name.
Each change started from a failing test.