Open and answer this issue on GitHub.
ready · opened 2026-11-08 · updated 2026-11-08 · 0 comments
Found in the run of #1401.
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 }
k: !e!foo x\n gives 1:11: expected is_uri(x) && …; found x. That is TagChar’s guard, one byte past the tag, from the TagChar+ try that backtracked.- !e!foo x\n gives 1:9: expected a tag handle a %TAG directive declares. This one is right.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.
ParseContext::best and the stream chunk path.rev in Cargo.toml (as in e265d24fa).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.keywan-ghadami/winnow-grammar. The driver’s sessions cannot push there, so step 1 needs someone with write access to that repository.The test is green, and #1401’s probe k: !e!foo x reports 1:10 with the guard’s message.