ini

    High-performance INI parser for MoonBit with nested section support.

    ini
    parser
    moonbit
    configparser
    Download zip
    Version
    0.2.3
    License
    Apache-2.0
    Last updated
    4 days ago
    Downloads
    47

    #📝 ini: A MoonBit INI Parser

    Build Status License codecov

    ini is a high-performance INI parser for MoonBit applications. It provides a simple and efficient way to parse and access INI configuration files with a clean and intuitive API.

    🚀 Key Features

    • 🔍 INI Parsing – Parse INI files with comprehensive error handling
    • đŸ›Ąī¸ Type Safety – Strongly typed access to configuration values
    • 🔄 Case Sensitivity Options – Configurable case sensitivity for section and key names
    • đŸŽ¯ Simple API – Easy to use with intuitive method names
    • đŸ“Ļ Zero Dependencies – Pure MoonBit implementation with no external dependencies


    #đŸ“Ĩ Installation

    moon add moonbit-community/ini

    #🚀 Usage Guide for ini

    ini provides a straightforward way to parse and access INI configuration files in your MoonBit applications.


    #📝 What is an INI File?

    An INI file is a configuration file format that consists of sections and key-value pairs:

    config.ini

    [server] host=localhost port=3000 [database] url=mysql://user:pass@localhost/dbname max_connections=100


    #🔍 Basic Usage

    The simplest way to use ini is with the parse function:

    ///|
    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")
    }

    #âš™ī¸ Configuration Options

    ini offers configuration options when parsing:

    ///|
    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)
    }


    #🔄 Value Access

    After parsing, you can access values using various methods:

    ///|
    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)")
    }


    #đŸ› ī¸ Full Example

    ///|
    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",
    )
    }

    #📜 License

    This project is licensed under the Apache-2.0 License. See LICENSE for details.

    #đŸ“ĸ Contact & Support

    👋 If you like this project, give it a ⭐! Happy coding! 🚀

    IniParseError

    pub suberror IniParseError {
    UnexpectedEqualSign(line~ : Int, col~ : Int)
    EmptySection(line~ : Int, col~ : Int)
    UnclosedSection(line~ : Int, col~ : Int)
    ValueWithoutSection(line~ : Int, col~ : Int)
    QuoteMismatch(line~ : Int, col~ : Int)
    QuoteNotClosed(line~ : Int, col~ : Int)
    }

    IniFile

    type IniFile

    IniFile::get

    fn IniFile::get(self : IniFile, section? : String, key : String) -> String?

    get is a alias for get_string

    IniFile::get_bool

    fn IniFile::get_bool(self : IniFile, section? : String, key : String) -> Bool?

    IniFile::get_string

    fn IniFile::get_string(self : IniFile, section? : String, key : String) -> String?

    IniFile::new

    fn IniFile::new(is_case_sensitive? : Bool) -> IniFile

    IniFile::set

    fn IniFile::set(self : IniFile, section? : String, key : String, value : String) -> Unit

    IniFile::to_string

    fn IniFile::to_string(self : IniFile) -> String

    Converts the IniFile to a standard INI format string

    IniParseState

    type IniParseState

    IniParseState::finish

    fn IniParseState::finish(self : IniParseState) -> IniFile raise IniParseError

    IniParseState::new

    fn IniParseState::new(is_case_sensitive? : Bool) -> IniParseState

    IniParseState::parse

    fn IniParseState::parse(self : IniParseState, chunk : String) -> IniParseState raise IniParseError

    parse

    fn parse(str : String, is_case_sensitive? : Bool) -> IniFile raise IniParseError

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    Š 2026 mooncakes.io