Open and answer this issue on GitHub.
ready · opened 2026-10-31 · updated 2026-10-31 · 1 comment
agent: builder model: opus max_turns: 60 budget_usd: 12 —
return inside a grammar action reaches rustc (what does it mean?)The architect probing the yaml lane’s next brief (y2b, 2026-10-31, develop 6064835c). An action that leaves early with return passes the checker; the emitter writes the action as a closure that must give Result<T, ErrMode<..>>, and the return gives T:
grammar G {
rule WS = "" -> { }
entry rule tag -> String = h:until("x") "x" -> {
for d in ["!e!"] {
if d == h {
return "found"
}
}
"other"
}
}
called as G::tag("!e!x"): rustc Mismatched types at the return, expected enum Result<&str, ErrMode<__WgEr>>, found &'static str (the same with a String result: found struct String). Part II 10 says nothing on return in an action; no ADR. So this is kind 2 (not decided), and in any case a rustc error is a defect: the checker must give an answer.
return e in an action gives the action’s value e, as in a function body: the action is a block that computes the rule’s value, and return is how Nikaia leaves a block early. The emitter wraps it (return Ok(e)), the checker checks e against the rule’s type. Cost: one emitter arm, one checker rule, one Part II sentence.return in an action is refused (an existing “return outside a function” code if one fits, else a new NK code from the supervisor). Cost: one checker rule; actions stay expressions without early exit (a let mut out and a loop, as today).Nothing in the yaml package needs it (it writes no return in an action).
tests/compiler/tests/grammar_an_action_returns_early.nika (A, .stdout found/other) or ..._is_refused (B, .stderr); Part II 10 one sentence.Generated by Claude Code
Owner decision (2026-10-31): A. A return x inside a grammar action ends the action with the value x, just as it would in a function body. The rule still matches; return never ends the parse. With this decision the issue is ready: a builder lowers the action into a body of its own so that return leaves that body, adds a tests/compiler test that uses an early return, and updates the grammar section of the specification. Nothing in yaml depends on this.
Generated by Claude Code