Issue #2602: The compiler reads TOML into a declared struct through a grammar (Toml::read[T])

Open and answer this issue on GitHub.

enhancement, selfhosting, ready, safety, queued · opened 2026-11-21 · updated 2026-11-29 · 1 comment

Owner, 2026-11-21: a TOML reader built on the grammar mechanism, reading a file into a declared struct, not into a dynamic tree: the program states what the file must say, the reader refuses everything else, and only the parser for that type runs (“Ich will ja die Sicherheit haben, dass genau das in der Datei steht, was wir erwarten. Und der Parser dann auch entsprechend schnell arbeiten kann.”).

Part of #2505 (its TOML half, built inside the compiler first) Needs #2599 Found while #2460 (its leftover “A TOML reader for the trust manifest” #2484 needs it)

Where it stands

Governing decisions

ADR-grammar-typed-read-v1 D1 (an entry takes a type), D2 (match T::kind), D3 (members[S]), D5 (missing and twice-written members are errors), D6 (Map(K, V) with text keys; a format offers the same mechanism, TOML named). Part III 13.3 (what nikaia.toml holds). The TOML format itself: TOML 1.0, of which this issue builds the subset below.

The form

grammar Toml {
	entry rule read[T: Struct] -> T = ...
}
struct Package { name: String, version: String = "0.0.0", }
struct Doc { package: Package, }
let d: Doc = Toml::read[Doc](text) catch { ... }

To build

  1. crates/nikaia-std/src/compiler/toml.nika: grammar Toml with entry rule read[T: Struct], lowered by lower-std like the other compiler modules. It reads: blank lines and # comments (whole line and after a value); [name] table headers; key = value lines with bare keys (A-Za-z0-9_-) and "quoted" keys; values by kind: Text a basic string "..." with the escapes \" \\ \n \t \uXXXX, I64 a decimal integer with an optional sign and _ between digits, Bool true / false, List(A) an array [a, b,] across lines with comments between, Maybe(A) the value or the key left out, Struct(_) an inline table { k = v, ... } or a [header] table. The document is the root struct’s members: each key line before the first header, each header a member whose value is the table’s lines. A table or key written twice is the D5 error. Test toml_reads_a_declared_struct.nika (a two-table document with every scalar kind, an array over three lines, an inline table, comments, a quoted key; prints each field) and toml_refuses_what_the_struct_does_not_say.nika (.stdout: an unknown key, a missing field, a key twice, a string where an integer belongs, each one line with line and column).
  2. Map fields: a field collections::BTreeMap[String, V] (and HashMap) is filled from a table’s keys, each value read as V: [dependencies] with name = { path = "..." } entries, and a table of tables. Needs #2599 built. Test toml_reads_a_table_into_a_map.nika (a map of inline tables and a map of strings, printed in key order).
  3. Dotted headers nest: [build.wasm] after [build] is the member wasm of the build value (a struct field or a map key), [allow.packages.json] two levels down. A dotted header whose parent table is not the open one ([a.b] before [a], or after [c]) is refused with its line and column: the subset reads tables in nesting order, which every nikaia.toml in the repository keeps (git ls-files '*nikaia.toml', 44 files). The builder chooses how the grammar says it; if no grammar form can say “a header continuing the open table”, that is a Found: (gap of kind 2), not a workaround. Test toml_a_dotted_header_nests.nika ([build], [build.wasm], [allow.packages.json]; and the refused order, its message).
  4. Every nikaia.toml in the repository reads: a test toml_reads_the_manifests.nika that declares the struct of item 1-3 for the sections the 44 manifests use (package, dependencies, build with its target tables, features, rust-library, directories, allow, library.<name>) and reads three representative ones copied in as text (one with [dependencies] inline tables, one with [features] arrays, one with [allow]), printing a line per section. A dependency written as a bare version (http_server = "1.2", Part III 13.3) is the manifest’s question (the next issue), not this one: this test uses table entries only.

Done when

Toml::read[T] reads a TOML document into a declared struct with map fields and dotted headers, refuses an unknown key, a missing field, a repeated key and a wrong kind each with line and column, and the four tests pass; the last code step carries Fixes #N, and the report has a Found: line per gap met.

Files and limits

Ruled out


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-22

Supervisor, 2026-11-22: item 1 is built in f6e6034b6 (Toml::read[T] in crates/nikaia-std/src/compiler/toml.nika). “A grammar cannot read a collections::HashMap[String, V] field” (#2599) is closed (a380fcd0e), so item 2 can go ahead. Queued in the safety lane for items 2-4: wip swapped for ready, safety added.


Generated by Claude Code

Back to Open Issues