feat: add Statements, the top-level statement iterator
Test / test (push) Successful in 1m36s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-22 01:12:04 +02:00
parent d92bb56853
commit a7a942a8e1
6 changed files with 233 additions and 0 deletions
+21
View File
@@ -97,6 +97,27 @@ interface flags the decoder and encoder resolve through are built once and
cached, so the first document pays the cost instead of the hot path. A `T`
that is not a struct warms nothing.
### `func Statements(r io.Reader) iter.Seq2[Statement, error]`
Iterates the top-level statements of the document r carries, in written
order: key/value statements, a `[table]` header as one statement carrying
its `Table` node, and an `[[array of tables]]` as one statement per element
with the element's node and its `Index`. Iteration stops at the first error
and at a false yield, so a caller looking for one section reads no further.
The reader is consumed in full before the first yield, because the parser
scans the source in place.
```go
for stmt, err := range interpres.Statements(file) {
if err != nil {
return err
}
if stmt.Table != nil {
fmt.Println(stmt.Key, stmt.Table.Keys())
}
}
```
## Documents
`Parse` returns a `Document`: the value tree together with what a map cannot