Issue #1413: grammar runtime: a cut’s error loses to a farther failure recorded before the cut

Open and answer this issue on GitHub.

ready · opened 2026-11-08 · updated 2026-11-08 · 0 comments

Found in the run of #1401.

What happens

After a cut p => q, a failure in q should be the error. In the grammar runtime (winnow-grammar 7235ce46, ParseContext::best and the Stop::Failed chunk in rt/stream.rs), the error is instead the farthest failure recorded so far, and that can be one from inside p, before the cut, which backtracked. Whether this happens depends on the context: it does in a block mapping value and after ---, but not at top level, in a sequence or in a flow collection.

Probe, with the cut in packages/yaml/src/main.nika:

rule Tag = s:text(TagForm) => if(declared(ds, s), "a tag handle a %TAG directive declares") -> { s }

Decided (supervisor, 2026-11-08)

This is a defect, not an open question. Part II’s table of grammar forms already says what should happen (p => q: “a failure in q is an error and no enclosing alternative is retried”), so the cut’s failure is the error. A failure recorded before the cut belongs to a branch that was already given up, and it does not compete with the cut’s failure. This should hold the same way in every context and on the whole-input and stream paths alike.

To build

  1. In winnow-grammar: once a cut has committed, a failure after it is reported as is. The farthest-failure merge only weighs failures recorded after the cut. This applies to both ParseContext::best and the stream chunk path.
  2. Bump the rev in Cargo.toml (as in e265d24fa).
  3. Add a test in tests/compiler/: a grammar whose p tries one byte past its end and whose q fails at that end, used in two contexts, both reporting q’s position and message.

Limits

Done when

The test is green, and #1401’s probe k: !e!foo x reports 1:10 with the guard’s message.

Back to Open Issues