A TOML v1.0.0 parser and serializer for MoonBit with full toml-test compliance.
// moon.mod: import { "sa2360/toml" }let doc = @toml.parse("title = \"Example\"\n[owner]\nname = \"Tom\"")
doc.get_string("title") // Some("Example")
doc.get_path("owner.name") // Some(Str("Tom")) — dotted path lookup
doc.get_int("port") // Option[Int64]
doc.get_double / get_bool / get_array / get_table / get_datetimelet text = @toml.encode(doc) // full document ([table] sections, [[array of tables]])
let inline = @toml.encode_value(v) // a single value in inline formlet json = value.to_json() // -> moonbitlang/core Json
let text = value.to_json_string() // compact JSON stringpub(all) enum Value {
Str(String); Int(Int64); Float(Double); Bool(Bool)
Datetime(Datetime); Array(Array[Value]); Table(Table)
}moon build --target native cmd/toml2json
_build/native/debug/build/cmd/toml2json/toml2json.exe config.tomlmoon test # 303 tests: unit + full embedded toml-test suite
moon bench # parse / encode / to_json benchmarks
moon build --target native cmd/toml2json
python scripts/run_toml_test.py # official protocol runner over the CLI (281 cases)value.mbt Value / Table / Datetime model, accessors, equality
error.mbt Position, ParseErrorData, ParseError
scanner.mbt cursor, whitespace/comment/newline handling, char classes
strings.mbt the four string kinds and escape validation
numbers.mbt integers, floats, datetimes (with range checks)
parser.mbt document/table/keyval/array/inline-table + definition rules
encode.mbt serializer (documents and inline values)
json.mbt JSON interop (to_json, ToJson impl)
cmd/toml2json/ native CLI emitting toml-test tagged JSON
cmd/example/ runnable demo: parse, read, re-encode, convert to JSON
scripts/ conformance generator + CLI runner
toml-test-tests/ vendored official suite (v1.0.0)let doc = @toml.parse("title = \"Example\"\n[owner]\nname = \"Tom\"")
doc.get_string("title") // Some("Example")
doc.get_path("owner.name") // Some(Str("Tom"))
let text = @toml.encode(doc) // 序列化回 TOML 文档
let json = @toml.Value::Table(doc).to_json_string() // 转 JSON(整数精度无损)let doc = @toml.parse(input) catch {
err => println(err.message()) // 例如:line 3, column 5: duplicate key 'apple'
}moon test # 303 个测试:单元测试 + 内嵌 toml-test 全量套件
moon bench # parse / encode / to_json 基准
moon build --target native cmd/toml2json
python scripts/run_toml_test.py # 官方协议 runner(281 个用例,含字节级 UTF-8 用例)impl Show for ParseErrorpub(all) enum ParseErrorData {
UnexpectedChar(Position, Char)
UnexpectedEof(Position)
UnterminatedString(Position)
InvalidEscape(Position, Char)
InvalidUnicodeEscape(Position, String)
InvalidNumber(Position, String)
InvalidDatetime(Position, String)
InvalidValue(Position, Char)
DuplicateKey(Position, String)
TableConflict(Position, String)
InvalidSyntax(Position, String)
} derive(Eq, Debug)pub struct Table {
// private fields
}Install
Download zipA TOML v1.0.0 parser and serializer for MoonBit with full toml-test compliance.