Sign in

    toml_parser

    A complete TOML (Tom's Obvious, Minimal Language) parser implementation in MoonBit with support for all basic types, arrays, tables, and nested structures.

    toml
    parser
    config
    configuration
    serialization
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    11 months ago
    Downloads
    35

    No dependencies

    #TOML Parser

    A complete TOML (Tom's Obvious, Minimal Language) parser implementation in MoonBit.

    #Features

    • ✅ Basic Types: Strings, integers, floats, booleans
    • ✅ Arrays: Including nested arrays and mixed-type arrays
    • ✅ Tables: Nested tables, dotted keys, inline tables
    • ✅ Comments: Line comments with #
    • ✅ Escape Sequences: Support for \n, \t, \r, \\, \"
    • ✅ Number Formats: Underscores in numbers, scientific notation
    • ✅ Error Handling: Comprehensive error messages with type-safe error propagation

    #Quick Start

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

    #API Documentation

    #Main Functions

    #parse(input : String) -> TomlValue raise

    Parses a TOML string and returns a TomlValue representing the parsed document.

    #Data Types

    #TomlValue

    pub(all) enum TomlValue {
    String(String)
    Integer(Int64)
    Float(Double)
    Boolean(Bool)
    DateTime(String)
    Array(Array[TomlValue])
    Table(Map[String, TomlValue])
    }

    #Examples

    #Basic Values

    # String greeting = "Hello, World!" # Integer count = 42 # Float pi = 3.14159 # Boolean enabled = true

    #Arrays

    # Simple array numbers = [1, 2, 3, 4, 5] # Mixed-type array mixed = ["hello", 42, true, 3.14] # Nested array matrix = [[1, 2], [3, 4]]

    #Tables

    # 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 }

    #Running

    # Run tests moon test # Run demo moon run cmd/main # Type check moon check

    #License

    MIT License

    Lexer

    type Lexer

    Lexer state

    Parser

    type Parser

    Parser state

    Token

    type Token

    Token types for the lexer
    impl Eq for Token
    impl Show for Token

    TomlValue

    pub(all) enum TomlValue {
    String(String)
    Integer(Int64)
    Float(Double)
    Boolean(Bool)
    DateTime(String)
    Array(Array[TomlValue])
    Table(Map[String, TomlValue])
    }

    TOML Value - represents any TOML value
    impl Eq for TomlValue
    impl Show for TomlValue

    TomlValue::to_pretty_string

    fn TomlValue::to_pretty_string(self : TomlValue) -> String

    Convert TomlValue to a pretty string

    parse

    fn parse(input : String) -> TomlValue raise

    Parse the entire TOML document

    Source Files