This is a TOML v1.0.0 parser library, with dates supporting nanosecond precision. It passes all tests in toml-test v1.3.0. Click the "TOML Compliance" badge for logs of toml-test.
This code is a fork of Greg Hendershott's TOML parser. Unlike that repository, this version is available on pkgs.racket-lang.org and includes support for generating TOML.
raco pkg install --auto toml(require toml)
(parse-toml s) ;; where `s` is a `string?`Sample output of a program such as
#lang racket
(require toml)
(define sample-expr
'#hasheq((table . #hasheq((key . 5)
(array . (#hasheq((a . 1) (b . 2))
#hasheq((a . 2) (b . 4))))))
(|another-table| . #hasheq((key . 10)))))
(display (tomlexpr->string sample-expr))would be
[another-table]
key = 10
[table]
key = 5
[[table.array]]
a = 1
b = 2
[[table.array]]
a = 2
b = 4
-
Remain current with the most recent TOML release version.
-
Provide useful error messages with positions (line:col:ofs). Do so for both syntax errors and semantic errors (such as table conflicts).
-
Return a Racket
hasheqthat satisfies thejsonlibrary'sjsexpr?predicate, so that you can run it throughjsexpr->stringto produce a JSON string.Caveat: Any TOML datetime values are
datestructs, which won't satisfyjsexpr?. Originally I parsed these to acurrent-seconds-style integer value. Buttoml-testsneeds things to be tagged with types, so that's why I had to switch. I should probably provide a conversion function to turn any such instances back into a datetime string so that it can be passed tojsexpr->string.