Skip to content

Follow the SPARQL grammar when looking for an undeclared prefix - #26

Merged
nertzy merged 1 commit into
mainfrom
prefix-scan-grammar
Nov 17, 2026
Merged

nertzy merged 1 commit into
mainfrom
prefix-scan-grammar

Conversation

@nertzy

@nertzy nertzy commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

The scan that names an undeclared prefix (#24) disagreed with the SPARQL grammar on unusual text. In those cases the error blamed a prefix that was declared, or something that was not a prefix at all, which is worse than the parser's own message. This makes the scan's tokens follow the terminals of the grammar the parser uses, and ends the scan where it would have to guess.

What changes

Text Before Now
A comment ended by a carriage return, then a PREFIX line Blamed the declared prefix The parser's message
A comment between PREFIX and the prefix it declares Blamed the declared prefix The parser's message
An IRI that never closes, such as <urn:foo Blamed urn: The parser's message
?o-ex:a Blamed : Names ex:
A blank node label with an inner dot, such as _:b.PREFIX Could read PREFIX as a declaration Names the prefix that follows
A prefix or local name with a combining mark or a middle dot Blamed a truncated name Follows the grammar's name characters
An undeclared prefix after a < comparison, such as ?o < 18 or ?s < ex:a Named The parser's message
An undeclared prefix inside or after an embedded triple, such as << ?s ?p ex:a >> Named The parser's message

One trade-off

A < is a comparison, the start of an embedded triple, or the start of an IRI, and only a parse can tell which. The scan steps over a < only when an IRI opens there and closes. Any other < ends it.

So a prefix is named when it comes before the first comparison or embedded triple. After that the parser's own message stays, which is vaguer and not wrong. The README says so.

An earlier version of this pull request tried to tell the three apart from the characters around the <. Review kept finding text that fooled it, so that logic is gone.

Known limit

A < followed by a > with no white space between them still reads as an IRI. A comparison written without spaces can match that by accident, as in FILTER(?a<'x>ex:p'). The scan then reads the rest of the string as query text and names ex:. This is unchanged from main.

Each case started from a failing test. The comments this answers are on #24, which merged before they were addressed, and on this pull request.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 05:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The prefix scanner misses undeclared prefixes in compact embedded triples and falsely reports prefixes inside digit-led unterminated IRIs, masking the parser’s diagnostic.

2 open issues
What changed in this PR

Refines the undeclared-prefix diagnostics introduced in #24 by aligning the fallback scanner more closely with SPARQL grammar, reducing misleading errors on unusual input.

Changes:

  • Updates handling of comments, names, variables, language tags, and blank node labels.
  • Preserves parser errors when an apparent IRI is unterminated.
  • Adds Ruby regression tests for unusual token boundaries and Unicode names.
File Description
test/​test_query.rb Adds regression cases for corrected prefix detection and parser-error preservation.
ext/​oxigraph/​src/​prefix.rs Refines scanner character rules, token boundaries, and unterminated-input handling.

Review effort: Balanced

Comment thread ext/oxigraph/src/prefix.rs Resolved
Comment thread ext/oxigraph/src/prefix.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The diagnostic scanner still misidentifies prefixes in exponent comparisons and comment-delimiter cases, and malformed input can trigger quadratic scanning time.

3 open issues
2 resolved since last review

Review effort: Balanced

Comment thread ext/oxigraph/src/prefix.rs Resolved
Comment thread ext/oxigraph/src/prefix.rs Resolved
Comment thread ext/oxigraph/src/prefix.rs Resolved
The scan that names an undeclared prefix disagreed with the grammar on
unusual text, and then blamed a prefix that was declared or was no prefix
at all. A comment now ends at a carriage return as well as a line feed, and
may sit between PREFIX and the prefix it declares. A variable name no longer
takes in a hyphen, a blank node label keeps its inner dots, and a name may
hold the combining marks and other characters the grammar allows.

A "<" is a comparison, the start of an embedded triple, or the start of an
IRI, and only a parse can tell which. The scan steps over a "<" only when an
IRI opens there and closes; any other "<" ends it, and the parser's own
message stays. So a prefix is named when it comes before the first
comparison or embedded triple, and the README says so.
@nertzy
nertzy force-pushed the prefix-scan-grammar branch from 41e8a1e to 4457d35 Compare November 17, 2026 15:27
@nertzy
nertzy merged commit 07643fc into main Nov 17, 2026
11 checks passed
@nertzy
nertzy deleted the prefix-scan-grammar branch November 17, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants