TOML parsing for the Donna programming language.
parsetoml parses a practical subset of TOML into Donna values.
It supports strings, integers, booleans, arrays, inline tables, sections, nested sections, line comments, and inline comments.
Add to your donna.toml as a dependency:
[dependencies]
parsetoml = { git = "https://github.com/donna-lang/parsetoml", version = ">=0.1.0 and <1.0.0" }Then import the module:
import parsetoml
import parsetoml
pub fn parse_config() -> String:
let src = "name = \"site\"\n[build]\noutput = \"public\""
let toml = parsetoml.unwrap_table(parsetoml.parse(src))
parsetoml.get_string(toml, "name")
|> parsetoml.unwrap_string
Read nested tables:
import parsetoml
pub fn build_output() -> String:
let src = "[build]\noutput = \"public\""
let toml = parsetoml.unwrap_table(parsetoml.parse(src))
case parsetoml.get_table(toml, "build"):
parsetoml.Err(_) -> ""
parsetoml.Ok(build) ->
parsetoml.get_string(build, "output") |> parsetoml.unwrap_string
Run tests:
donna testFor API Reference visit the generated docs here
name = "value"
path = '../lib'
count = 42
enabled = true
items = ["a", "b"]
pkg = { path = "../lib", version = "0.1.0" }
[build]
output = "public"
[site.menu]
weight = 10Not supported yet: floats, dates, multi-line strings, and array-of-tables.
MIT