A complete TOML (Tom's Obvious, Minimal Language) parser implementation in MoonBit with support for all basic types, arrays, tables, and nested structures.
fn main {
let toml_content = "name = \"MoonBit\"\nversion = 1"
try {
let result = @maria/toml_parser.parse(toml_content)
println(result.to_pretty_string())
} catch {
e => println("Parse error: \{e}")
}
}pub(all) enum TomlValue {
String(String)
Integer(Int64)
Float(Double)
Boolean(Bool)
DateTime(String)
Array(Array[TomlValue])
Table(Map[String, TomlValue])
}# String
greeting = "Hello, World!"
# Integer
count = 42
# Float
pi = 3.14159
# Boolean
enabled = true# Simple array
numbers = [1, 2, 3, 4, 5]
# Mixed-type array
mixed = ["hello", 42, true, 3.14]
# Nested array
matrix = [[1, 2], [3, 4]]# Table section
[database]
host = "localhost"
port = 5432
# Nested tables
[server.connection]
timeout = 30
max_retries = 3
# Dotted keys
user.name = "Alice"
user.age = 30
# Inline table
point = { x = 10, y = 20 }# Run tests
moon test
# Run demo
moon run cmd/main
# Type check
moon checktype TokenInstall
Download zipA complete TOML (Tom's Obvious, Minimal Language) parser implementation in MoonBit with support for all basic types, arrays, tables, and nested structures.