feat: add ParseFile and Valid
Test / test (push) Successful in 2m33s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-21 23:51:58 +02:00
parent ce0c1ebd9d
commit 3cc168f39a
4 changed files with 101 additions and 0 deletions
+23
View File
@@ -50,6 +50,29 @@ tree, err := interpres.ParseMap([]byte("title = \"x\"\nport = 8080\n"))
The cancellable variant of `ParseMap`.
### `func ParseFile(path string) (*Document, error)`
Reads the file at `path` and parses it into a [Document](#documents), the shape
`Parse` gives. Both a read failure and a parse failure come back with the file
name as their first words, wrapped so `errors.AsType` still reaches the
`SyntaxError` inside a parse failure.
```go
doc, err := interpres.ParseFile("config.toml")
```
### `func Valid(data []byte) error`
Reports whether `data` is a valid TOML document: `nil` when the parser accepts
it, the parse error when it does not. It is the library call the `-validate`
mode of interpres-decode is built on.
```go
if err := interpres.Valid(data); err != nil {
fmt.Println("invalid:", err)
}
```
## Documents
`Parse` returns a `Document`: the value tree together with what a map cannot