High-performance INI parser for MoonBit with nested section support.
moon add ShellWen/sw_ini[server]
host=localhost
port=3000
[database]
url=mysql://user:pass@localhost/dbname
max_connections=100fn main {
let config_str = "[server]\nhost=localhost\nport=3000"
let ini = @sw_ini.parse!(config_str)
let host = ini.get(section="server", "host").unwrap()
println("host=\{host}")
}// Case-sensitive parsing
let ini = @sw_ini.parse!(content, is_case_sensitive=true)
// Create an empty INI file object
let ini = @sw_ini.IniFile::new(is_case_sensitive=true)let ini = @sw_ini.parse!(content)
// Get string value (with optional section)
let host = ini.get(section="server", "host")
// Get boolean value
let enabled = ini.get_bool(section="feature", "enabled")
// Get with default section (global)
let global_value = ini.get("global_key")match @sw_ini.parse?(content) {
Ok(ini) =>
// Use the INI file
println("Parsed successfully")
Err(e) =>
// Handle parse error
println("Error parsing INI file")
}fn main {
let content = #|[server]
#|host=localhost
#|port=3000
#|enabled=true
#|
#|[database]
#|url=mysql://localhost/db
// Parse INI content
let ini = @sw_ini.parse!(content)
// Access various values
let host = ini.get(section="server", "host").unwrap()
let port = ini.get(section="server", "port").or("8080")
let enabled = ini.get_bool(section="server", "enabled").unwrap()
// Use values in your application
if enabled {
println("Server running at \{host}:\{port}")
}
}type IniFilepub enum IniParseError {
UnexpectedEqualSign(Int, Int)
EmptySection(Int, Int)
UnclosedSection(Int, Int)
ValueWithoutSection(Int, Int)
QuoteMismatch(Int, Int)
QuoteNotClosed(Int, Int)
}type IniParseStateInstall
Download zipHigh-performance INI parser for MoonBit with nested section support.