Issue #1216: Grammars: uncaught entry reaches rustc, cut inside recover ends the parse, repeated dec[T] in a lowercase rule, left recursion unspecified

Open and answer this issue on GitHub.

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

Found while writing the grammars chapter of the guide (d2, guide/grammars.md).

1. An uncaught grammar entry reaches rustc instead of NK2605

grammar P { entry rule n -> i64 = x:dec[i64](digit+) -> { x } }
fn main() { let v = P::n("1"); println(f"{v}") }

Expected: NK2605. Actual: rustc says “The ? operator can only be used in a function that returns Result”.

2. A cut inside recover(p, sync) ends the whole parse

entry rule block -> Vec[i64?] = "{" => xs:recover(stmt, ";")* "}" -> { xs }
rule stmt -> i64 = "let" => n:dec[i64](digit+) ";" -> { n }

With the input "{ let 1; let x; let 3; }", the parse fails at x. Without the inner => it gives 1, null, 3. The recovered failure’s message also never reaches the program, although Part II 10.6 and 10.8 say “p’s value or the report”.

3. A repeated dec[T](digit+) in a lowercase rule

entry rule i -> Vec[i64] = xs:dec[i64](digit+)* eof -> { xs }

On "1 2" this errors “expected a digit” instead of ending the repetition. The same inside an uppercase rule gives 2 items. Also, an overflowing dec reports “expected a digit” at the next character, not that the number does not fit.

4. Left recursion works but is unspecified

expr = a:expr "-" b:NUM | n:NUM gives 10-3-2 = 5 today. Part II does not specify it, and the comment in examples/calc says it would never terminate.

To build

  1. Item 1: NK2605 for an entry called outside catch / throws, with a test in tests/compiler/.
  2. Item 2: a cut inside recover commits only within p; the report reaches the program as 10.6/10.8 say; tests.
  3. Item 3: repetition stops on a failed dec in a lowercase rule, and an overflow names the overflow; tests.
  4. Item 4: a supervisor decision on whether left recursion is specified (Part II text) or refused. Fix the calc comment either way.

Back to Open Issues