Grammar notes

Known ambiguities and resolution

  • if expression vs if statement:
  • Resolution: statement is parsed in block statement context, expression in expression context.
  • when clause vs when ... is match guard:
  • Resolution: when <expr> is <pattern> is preferred when is token is present.
  • use single path vs grouped path:
  • Resolution: parser reads .{ as group start and .* as glob import.
  • generic call vs index then call:
  • Surface syntax allows foo[T](...).
  • Current resolution: The parser only chooses the generic call when the bracketed content is an unambiguous list of types; otherwise it remains on normal indexing followed by a call.
  • Example: id[int](1) is a generic call, while id[i](1) remains index then call.

Top-level matrix / statement / expression

BuildTop-levelStatementExpression
procyesnoyes (proc_expr)
entryyesnono
ifnoyesyes
matchnoyesno
emitnoyesno
call (foo())noyes (expr_stmt)yes

Quick reading guide

  1. Starting from program and toplevel.
  2. Validate the boundaries of stmt before debugging expression precedence.
  3. Use the precedence.html priority table when the parsing of an operator seems incorrect.
  4. Reproduce with minimal file in tests/grammar.
  5. Check the diagnostics contract (docs/book/grammar/diagnostics/expected).

Current semantic boundary

  • The EBNF intentionally accepts the full borrow-related surface: &, & mut, move, projected paths such as x.field, and projected assignment targets via set.
  • That does not mean every accepted surface is fully modeled semantically yet. Parsing is broader by design; semantic rejection belongs to sema, typeck and borrowck.
  • Current borrowck status: structured Place names are propagated through HIR/MIR, copy-vs-move is partially type-driven, and loans now expire with lexical scope metadata.
  • Remaining limits: the ownership table is still indexed by name, not by a fully canonical place key; the dataflow merge is not yet a fully place-sensitive lattice across projections; region closure is still not driven by a final CFG-complete scope model.