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)
nikaia.toml with the Rust toml crate (Manifest::parse in crates/nikaia/src/manifest.rs, toml::from_str) and hands manifest_parse (crates/nikaia-std/src/compiler/manifest.nika) a flat list of ManifestItems, every value as its text.match T::kind in a rule, members[S](key, value, sep; null:, unknown:) filling a struct (ADR-grammar-typed-read-v1 D1-D5; tests grammar_members_builds_a_struct, grammar_members_a_member_twice_fails, grammar_members_a_missing_field_fails). A missing field already says the field x is missing at line 1, column 7.toml (#2505) cannot be used across packages yet: pub grammar waits for “Build ADR-296 D25: pub grammar” (#520). So this grammar lives in the compiler’s sources, where its first reader is; moving it into packages/toml stays with #2505.[dependencies], [build.<target>], [library.<name>], [allow.packages.<name>]) needs the Map(K, V) arm, which fails today with NK1250 (#2599).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.
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 { ... }
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).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).[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).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.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.
crates/nikaia-std/src/compiler/toml.nika, its lowered .rs (output of lower-std), the tests named above.check_core_pilot.nika / grammar_types.nika / emit_grammar.nika.crates/nikaia/src/manifest.rs and manifest.nika (the next issue switches the manifest), packages/json, packages/yaml.toml::parse into a Value tree and a walk: refused by the owner and by ADR-grammar-typed-read-v1 (option C, a tree and a second pass at every read).packages/toml now: blocked by pub grammar (#520); the grammar moves there with #2505.[[array of tables]], dotted keys on the left of =): no nikaia.toml in the repository uses them; each is its own issue when a reader needs it.Generated by Claude Code
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