Skip to content

Add the structural resolver: case selection plus positional routing - #578

Merged
Smaug123 merged 1 commit into
mainfrom
argparser-resolver
Jul 25, 2026
Merged

Add the structural resolver: case selection plus positional routing#578
Smaug123 merged 1 commit into
mainfrom
argparser-resolver

Conversation

@Smaug123

Copy link
Copy Markdown
Owner

Stage 5a of the positional-args-with-unions stack (5/8). Stacked on #577.

Adds the pure structural resolver: resolve (schema) (observed) (positionalEvents) : Selection, which performs case selection and positional routing together, before any value conversion. Conversion failures can therefore never influence which case wins or where a token goes.

Algorithm: intersect the events' candidate sets; for each candidate sink, form the hypothesis "this sink is active" by re-running selection with the sink as an extra observed leaf (selectWith); classify hypotheses as clean, fully valid, or internally ambiguous (the sink is routable but multiple interpretations through it accept); aggregate. New SelectionErrors: UnroutablePositional (no sink can take a token — including when the candidate intersection is empty, which is now always reported alongside the named-only diagnosis) and AmbiguousPositionalRouting.

The centrepiece test is an equivalence property against the Stage 2 exhaustive reference semantics (3000 generated cases per run, with distribution counters to confirm the generator exercises ambiguous/unroutable regions). This property caught a real bug during development: hypotheses whose only errors were empty-case ambiguities were being discarded as incoherent, letting a different sink win "uniquely" where the definitional semantics says the parse is ambiguous. The innerAmbiguous classification is the fix; 120k cases pass after it.

🤖 Generated with Claude Code

@Smaug123
Smaug123 force-pushed the argparser-candidate-scan branch from 704d73d to bd4c15b Compare July 25, 2026 10:26
@Smaug123
Smaug123 force-pushed the argparser-resolver branch from e6f154f to 9bdb4ab Compare July 25, 2026 10:26
@Smaug123
Smaug123 force-pushed the argparser-candidate-scan branch from bd4c15b to 723c144 Compare July 25, 2026 10:33
@Smaug123
Smaug123 force-pushed the argparser-resolver branch from 9bdb4ab to 7695eba Compare July 25, 2026 10:33
Base automatically changed from argparser-candidate-scan to main July 25, 2026 10:43
`resolve` chooses a case for every Sum and routes the positional
stream, before any conversion: it intersects the events' candidate
sets and runs the compositional selector once per candidate sink, the
sink treated as one additional observed leaf. A unique fully-accepting
hypothesis wins; several (including a single sink whose interpretation
is ambiguous through untouched empty-satisfiable cases) report
ambiguity; a hypothesis unique up to missing required arguments is
still selected so the missing arguments surface through the ordinary
channel; and when no sink fits, the named-only diagnosis is preferred,
with the routing contradiction reported when the events share no
candidate at all.

Two new selection errors carry the routing failures
(UnroutablePositional, AmbiguousPositionalRouting). Not yet wired into
runParse — that is the next stage — so generated parsers are unchanged.

The oracle: a property pinning `resolve` equivalent to the exhaustive
reference semantics over generated trees and inputs (it caught one
real bug during development: a sink whose interpretations were
ambiguous was silently discarded, letting another sink win uniquely).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Smaug123
Smaug123 force-pushed the argparser-resolver branch from 7695eba to 36f624b Compare July 25, 2026 10:52
@Smaug123
Smaug123 merged commit 45fefd1 into main Jul 25, 2026
19 checks passed
@Smaug123
Smaug123 deleted the argparser-resolver branch July 25, 2026 11:13
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.

1 participant