Repository navigation
test(grammar): bounded-exhaustive parser vs grammar.pest verifier (#643 PR 3) - #652
Merged
Merged
Conversation
src/query/datalog/parser/verifier.rs (test-only, not wasm32) checks every 1-3 character string through parse_edn and every balanced filler of up to MINIGRAF_GRAMMAR_BOUND (default 3) of 32 tokens in 15 command templates through parse_datalog_command against grammar.pest: pest rejects => parser rejects; pest accepts => parser accepts or raises a SEMANTIC code (each with a witness). Today's drift is KNOWN_DRIFT, one entry per cause, each failure put down to its first cause in text order (#649, #650, #651). grammar.pest: exact fact and retract_fact, edn_value_only, reserved list heads are never rule names, literal keywords end at a word boundary. The two arity corpus files move to invalid/syntax/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
4 tasks
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.
PR 3 of #643 (plan
docs/superpowers/plans/2026-10-20-643-grammar-verifier.md, steps 6–13): the verifier. Part of #643; does not close it.What
src/query/datalog/parser/verifier.rs,#[cfg(all(test, not(target_arch = "wasm32")))], pest-derived fromtests/grammar/grammar.pest. For every generated input: pest rejects ⇒ parser rejects; pest accepts ⇒ parser accepts or rejects with aSEMANTICcode.edn_value_onlyvsparse_edn(1,071,714 inputs).MINIGRAF_GRAMMAR_BOUND(default 3) of the 32 tokens in 15 templates (plan step 9),commandvsparse_datalog_command, plus a no-separator variant for fillers of ≤ 3 tokens. Filler counts are tested against the spec (18,516 at k=3, 487,678 at k=4).SEMANTIC(built from an empty-list run at k=3 and k=4, every site reviewed):PRS-021,PRS-022,PRS-080(2 sites),PRS-084,PRS-107, each with a witness tested to be pest-accepted and raise exactly that code.KNOWN_DRIFT, issues filed: Grammar: document or drop line comments and non-ASCII identifiers #650 (comments, non-ASCII letters: documentation decision), Parser accepts inputs the grammar rejects (empty sections, unknown keywords, rule/call heads, lexical edge cases) #651 (parser tightenings, v3.0.0: unterminated string, bare:, lone-, empty query/:find/:where/:with, ignored unknown keyword, section resumed after:as-ofetc., call/aggregate/rule heads), Fact with more than 4 elements: elements after the valid-time map are silently dropped #649 (fact of 5+ elements loses data:bug/data-integrity/known-issue, listed in Known issues in the current release (v2.x) #421; v3 fix then main backport).Deviations from the plan (need approval)
grammar.pestinstead of listed as drift (like plan deviation 1). Without these, 155k of 187k structural failures were pest's fault:rule_invocationmatchednot,not-join,or,or-joinas rule names, so(not 1)was a "rule call" to pest. Now!reserved_head; inside anor,(and …)is never a rule call.":find",":order-by", …) had no end-of-word check, so(:order-by?x)was:order-by ?xto pest and the unknown option:order-by?xto the parser (PRS-039). Each is now an atomickw_*rule with!word_cont. The plan put this with the empty-:findfix; it showed up now, so it is here.lexical_cause,structural_cause), so an input matches at most one entry and the "exactly one" rule holds by construction; unmatched failures and stale entries still fail. The structural causes read the parser's own EDN tree of the input, not the filler tokens: in the glued variant, tokens merge (:find?xis one keyword to the parser).UnterminatedString,EmptyQuery,EmptyWhere,ResumedSection,AggregateHead(k=4). Merged:rule-head-argsisRuleHead. Dropped:udf-var-head(needs 5 tokens, beyond the scheduled bound; listed in Parser accepts inputs the grammar rejects (empty sections, unknown keywords, rule/call heads, lexical edge cases) #651).SEMANTICis smaller than the plan expected. With the grammar fixes,PRS-051,PRS-093andINT-016are now syntax (pest rejects too). The others the plan expected (PRS-023,027,031/032/034,057,064,065,082,INT-018) are raised by no generated input at k ≤ 4, so they have no generated witness and are left out (the rule in step 10).Timing (step 12)
Debug
cargo test, 16-thread machine, load ~7 from another session (not idle, so approximate). Levels run on scoped threads (lexical by length × first-character range, structural one thread per template), merged in input order.Default stays k=3 (≈35 s on a 4-core runner); the scheduled job (PR 5) runs k=4. k=5 does not fit 30 minutes.
Review
Codex: one finding (unknown valid-time keys counted as
FactArity), declined — the parser rejects an unknown key with PRS-088 both with and without trailing elements, so pest and parser agree; only a valid map followed by extra elements isFactArity.Tests
1650 tests (1640 passing, 10 ignored): 4 new.
grammar_conformancepasses with the two arity files moved toinvalid/syntax/.MINIGRAF_GRAMMAR_BOUND=0..4all pass.🤖 Generated with Claude Code
https://claude.ai/code/session_019kY61Y11gcRD91Y6b7jbGT