fix(parser): handle N3 verb edge cases - #719
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes are cohesive, direction handling is consistently applied via a single quad creation path, and the added tests directly cover the reported edge cases and nesting/punctuation boundaries.
Pull request overview
This PR tightens N3 parsing/tokenization around the has, is, and of verbs to avoid keyword preemption of longer prefixed names (including across stream chunks) and to correctly scope/apply inverse-predicate state across punctuation and nested constructs (blank node property lists, formulas, triple terms, and reified triples), with regression tests added for the edge cases.
Changes:
- Add lexer logic to prefer longer prefixed names over N3 verb keywords when the verb is a prefix-start (including split chunk scenarios), while still recognizing numeric-boundary cases like
has1. - Refine parser inverse-predicate state handling to persist across commas, reset across semicolons/annotation boundaries, and apply inversion consistently when closing nested scopes and constructing triple terms / reified triples.
- Add regression coverage for inverse-predicate scoping and verb/prefix tokenization edge cases.
File summaries
| File | Description |
|---|---|
src/N3Lexer.js |
Adds _matchN3Verb to avoid verb keyword tokenization when a longer prefixed name is possible, including across stream chunks. |
src/N3Parser.js |
Centralizes direction-aware quad creation/emission and resets/scopes inverse-predicate state across punctuation and nested constructs. |
test/N3Lexer-test.js |
Adds lexer regression tests for numeric boundaries and keyword-like prefixes (including chunk-splitting). |
test/N3Parser-test.js |
Adds parser regression tests for inverse scoping across , / ;, blank node property lists, formulas, triple terms, reification, and annotations. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Performance follow-up for the inverse-handling concern: I benchmarked The initial implementation routed every Latest results (negative values are faster):
There is no measured non-N3 regression beyond the process/JIT/GC noise visible in the A/A controls. The only positive aggregate result is N-Triples at +0.7%; its paired result is 1.1 percentage points above its +2.3% A/A control, while its ordinary emission code is source-identical to Verification on the revised branch: 6,876 tests pass with 100% statement/branch/function/line coverage; ESLint and the Node, IIFE, and ESM builds pass. |
|
🎉 This PR is included in version 2.7.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
has,is, andofverbs from preempting longer valid prefixed names, including across stream chunksThis is a follow-up to #694.
Verification