Context-aware ILO-P009 hints for ternary-brace misfires#508
Merged
Conversation
When the parser hits `{` mid prefix-ternary operand parse, emit one of
two hints instead of the bare "expected expression, got `{`":
1. Match-on-value shape (`?h x{0:1;_:2}`): the agent reached for
Rust-style `match x { 0 => ..., _ => ... }` with a leading `?h`
keyword. Hint funnels them to `?<oper>{...}` (single-token) or
`?(<expr>){...}` (multi-token).
2. Three-form conditional confusion (`?h cond{body}`): the brace body
is not a match arm. Hint enumerates all three canonical shapes,
prefix-ternary `?h cond a b`, brace-ternary `cond{a}{b}`, and
braced-conditional `cond{body}`, with the parsed condition
substituted in so the agent can copy directly.
Match-arm shape is detected by peeking one token past the `{` for a
literal-and-colon pattern (`<num>: ...` or `"text": ...`). Pure
lookahead, no token consumption.
Hint fires in both statement (parse_match_stmt) and expression
(parse_prefix_ternary) positions so RHS-of-binding usage gets the
same diagnostic.
Six regression tests:
- match-arm shape fires the match-on-value hint and points at the
parenthesised or single-token recovery form
- match-arm hint uses the parsed first operand as the suggested match
subject (not the outer subject `h`)
- `?h cond{body}` fires the three-shape hint and does NOT misfire as
match-on-value
- same shape in expr position (RHS of binding) gets the same hint
- canonical `?(<expr>){...}` and `?h cond a b` still parse cleanly
Parser-layer codes are front-end only, so VM exercises the same path
the tree and Cranelift engines would. No engine-specific assertions
needed.
examples/match-on-value.ilo pins the two shapes the new ILO-P009 hint
funnels agents toward: single-token `?subj{lit:body;...}` and
multi-token `?(<expr>){lit:body;...}`. The example is picked up by
the examples_engines test harness so it doubles as a higher-level
regression test for the canonical match forms.
skills/ilo/ilo-language.md gets a one-line conditional section
contrasting the three canonical shapes so the persona-side agent
spec mirrors what the hint suggests. Also notes the multi-token
match-subject paren form on the existing match line.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
The conditional contrast addition pushed the file from 987 to 1096 tokens, over the per-module budget enforced by scripts/check-skill- tokens.py. Drop the bool-conditional section, the three shapes are already covered exhaustively in examples/conditional-shapes.ilo and SPEC.md (section 'Conditionals and Guards'). Keep the multi-token match-subject parens note since that's the canonical shape the new ILO-P009 hint funnels agents toward, and a one-line callout next to the match arms is the highest-value placement for it. Final: ilo-language at 999 tokens, total 6789.
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.
Summary
Two parser-diagnostic improvements on the
?-syntax family. Pending #5x and #6 in the assessment log, both tagged S, paired in one PR because they share a code path (the{token interception during prefix-ternary operand parse).Manifesto framing: a bare
ILO-P009 expected expression, got{`` is the worst kind of diagnostic for an LLM agent. No hint = no recovery path = a re-prompt that re-emits the same code (or worse, restructures and breaks something else). One persona run (cron-explainer) burned 167k tokens partly on this. All ten date/time personas tripped on the?h cond{body}variant. This PR turns those into actionable one-line hints.Repro before / after
?h x{0:1;_:2}(match-on-value shape):Before:
After:
?h ok{1}(three-form conditional confusion):Before:
After:
What's in the diff
Three commits:
add context-aware ILO-P009 hint for ternary-brace misfires(src/parser/mod.rs, +93)prefix_ternary_brace_hinthelper called from both statement (parse_match_stmt) and expression (parse_prefix_ternary) positions{for<num>:or<text>:test: cover ternary-brace hint shapes across both positions(tests/regression_ternary_brace_hint.rs, +151)?(expr){...}and?h a b cstill parsedocs: add match-on-value example and conditional contrast in skill(examples/match-on-value.ilo, skills/ilo/ilo-language.md)?subj{...}and?(expr){...}so the harness regresses bothTest plan
cargo build --release --features craneliftcleancargo test --release --features craneliftall green, 0 failurescargo clippy --release --features cranelift --all-targets -- -D warningscleancargo fmt --checkclean?(expr){...}and?h cond a bstill parse cleanlyFollow-ups
None blocking. The match-arm detector is intentionally conservative (one-token lookahead for
<num>:or<text>:); pattern arms with~v:/^e:/_:deliberately do NOT trigger the match-on-value framing since those are Result/Option destructuring, not value-equality matches.