High-performance INI parser for MoonBit with nested section support.
moon add moonbit-community/ini[server]
host=localhost
port=3000
[database]
url=mysql://user:pass@localhost/dbname
max_connections=100///|
test {
let config_str =
#|[server]
#|host=localhost
#|port=3000
let ini = @ini.parse(config_str)
let host = ini.get(section="server", "host").unwrap()
inspect(host, content="localhost")
}///|
test {
let content =
#|[server]
#|host=localhost
#|port=3000
#|[Server]
#|host=remote
// Case-sensitive parsing
let ini = @ini.parse(content, is_case_sensitive=true)
inspect(ini.get(section="server", "host").unwrap(), content="localhost")
inspect(ini.get(section="Server", "host").unwrap(), content="remote")
// Create an empty INI file object
let ini = @ini.IniFile::new(is_case_sensitive=true)
ignore(ini)
}///|
test {
let content =
#|[server]
#|host=localhost
#|port=3000
#|[feature]
#|foo=true
let ini = @ini.parse(content)
let host = ini.get(section="server", "host")
inspect(
host,
content=(
#|Some("localhost")
),
)
let foo_enabled = ini.get_bool(section="feature", "foo")
inspect(foo_enabled, content="Some(true)")
}///|
test {
let content =
#|[server]
#|host=localhost
#|port=3000
#|enabled=true
#|
#|[database]
#|url=mysql://localhost/db
// Parse INI content
let ini = @ini.parse(content)
// Access various values
let host = ini.get(section="server", "host").unwrap()
let port = ini.get(section="server", "port").unwrap_or("8080")
let enabled = ini.get_bool(section="server", "enabled").unwrap()
inspect(
if enabled {
"\{host}:\{port}"
} else {
""
},
content="localhost:3000",
)
}pub suberror IniParseError {
UnexpectedEqualSign(Int, Int)
EmptySection(Int, Int)
UnclosedSection(Int, Int)
ValueWithoutSection(Int, Int)
QuoteMismatch(Int, Int)
QuoteNotClosed(Int, Int)
}type IniFiletype IniParseStateHigh-performance INI parser for MoonBit with nested section support.