Issue #2625: A grammar members “is given twice” refusal points at the end of the list, not at the second key

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). Area: grammar emitter.

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

struct P { a: String, b: String, }
grammar G {
	rule WS = "" -> { }
	entry rule read[T: Struct] -> T = m:members[T](Key, Value[_], "\n") eof -> { m }
	rule Ch -> i64 = x:any if(x != '\n' && 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\na=2\nb=3\nb=4") catch {
		println(f"error: {error}")
		return
	}
	println(p.a)
}

Prints:

error: the field `a` is given twice at line 4, column 4
   4 | b=4
          ^
note: also possible here: `
`, any character
in __nikaia_members_0_more

Expected

error: the field a is given twice at line 2, column 1, pointing at the second a=. ADR-grammar-typed-read-v1 D3 says a field given twice fails; it names no position, but an error points at where the input is wrong, and that is the key that repeats, not the end of the list. The also possible here note does not belong to this refusal.

Cause (traced)

emit_members_rules in crates/nikaia-std/src/compiler/emit_grammar.nika (around line 1181) checks for doubles in the action of __nikaia_members_N after _all has read the whole list, so the input position is the list’s end.

To build

  1. Check for a double as each member is read (in _more, or by keeping each piece’s start offset), and throw at the key’s position.
  2. Add test tests/compiler/tests/grammar_members_twice_points_at_the_key.nika: the probe, with .stdout the line-2 refusal.

Done when

The probe prints the field a is given twice at line 2, column 1 under both settings.

Back to Open Issues