Issue #2624: A grammar members “is missing” refusal is replaced by a failure recorded further on

Open and answer this issue on GitHub.

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

Found while building the TOML reader for the compiler (#2602), inline tables. Area: grammar (winnow-grammar backend).

Probe (target/fast/nikaia run mi.nika)

struct P { a: String, b: String, }
grammar G {
	rule WS = "" -> { }
	entry rule read[T: Struct] -> T = "{" m:members[T](Key, Value[_], ",") "}" eof -> { m }
	rule Ch -> i64 = x:any if(x != ',' && x != '=' && x != '}') -> { 1 }
	rule Key -> String = s:text(Ch+) "=" -> { s }
	rule Value[T] -> T = match T::kind {
		Text => s:text(Ch+) -> { s }
	}
}
fn main() throws {
	let p: P = G::read[P]("{a=1}") catch {
		println(f"error: {error}")
		return
	}
	println(p.a)
}

Prints:

error: unexpected end of input, expected `x != ',' && x != '=' && x != '}'` at line 1, column 6
   1 | {a=1}
            ^
in Ch
in item 2
in Value__String

Expected

The refusal names the missing field: error: the field b is missing, at the end of the members list (line 1, column 5, the }). ADR-grammar-typed-read-v1 D3: a field left out with no default and not a T? fails the parse with the field named. The guard’s source text (x != ',' && ...) does not belong in an expected set either: it should name the rule (Ch).

Cause (suspected)

The members action throws through <__WgEr as Diagnostics>::external(..) as a Cut. winnow-grammar’s error merge (src/error.rs, merge, rev e417f40) ranks progress first, so the failure recorded one column further on (the x:any if(...) tried at end of input) wins over the Cut. Settling check: run the probe with the merge ranking a Cut from an action first.

To build

  1. Make an action’s Cut error (the members refusals) win over failures recorded inside the alternative that succeeded before it: in the merge, or by the emitter clearing the recorded failures before it throws.
  2. Show a guarded x:any if(...) in an expected set by its rule’s name, not the guard’s text.
  3. Add test tests/compiler/tests/grammar_members_missing_in_braces.nika: the probe, with .stdout the “is missing” refusal.

Done when

The probe prints the “the field b is missing” refusal under both settings.

Files: winnow-grammar (external, pinned rev) or emit_grammar.nika emit_members_rules.

Back to Open Issues