mojo-toml v0.2.0 π₯
The first native TOML 1.0 parser for the Mojo programming language!
This release provides full TOML parsing with proper nested table structures. Thanks to feedback from the Modular Discord community, we discovered the correct Dict iteration pattern and implemented nested tables from the start!
π Whatβs New
Core Parser - Fully Functional
- β 79 tests passing across 7 comprehensive test suites
- β Parses real-world TOML files (including pixi.toml)
- β Zero Python dependencies at runtime
- β Clear error messages with line/column information
Supported TOML Features
- Key-value pairs:
key = "value" - Comments:
# comment - Strings: basic, literal, multiline variants
- Numbers: integers, floats, special values (inf, nan)
- Booleans:
true,false - Arrays:
[1, 2, 3]with nesting and mixed types - Inline tables:
{name = "value"}with nesting - Table headers:
[section]with proper nested structures β¨ - Dotted headers:
[a.b.c]with deep nesting β¨ - Datetime strings (ISO 8601)
π¦ Installation
Recommended: Git Submodule
git submodule add https://github.com/databooth/mojo-toml vendor/mojo-toml
mojo -I vendor/mojo-toml/src your_app.mojoAlternative: Direct Copy
git clone https://github.com/databooth/mojo-toml
cp -r mojo-toml/src/toml your-project/lib/toml
mojo -I your-project/lib your_app.mojoCompiled Package
Download toml.mojopkg from this release (see compatibility note below).
π» Usage Example
from toml import parse
fn main() raises:
var config = parse("""
title = "MyApp"
version = "1.0.0"
[database]
host = "localhost"
port = 5432
""")
# Access root-level keys
print(config["title"].as_string()) # "MyApp"
# Access nested tables (proper structure!)
var db = config["database"].as_table()
print(db["host"].as_string()) # "localhost"
print(db["port"].as_int()) # 5432
π Major Feature: Nested Table Structures
Tables are now properly nested using Dict structures:
# Simple nesting:
var db = config["database"].as_table()
var host = db["host"].as_string()
# Deep nesting:
# [database.primary]
var db = config["database"].as_table()
var primary = db["primary"].as_table()
var host = primary["host"].as_string()
This was made possible by discovering that Mojoβs Dict iterator works with entry.key and entry.value directly!
π§ Known Limitations
Not yet implemented (planned for v0.3.0 - TOML 1.0 Compliance): - Array of tables: [[array]] - Duplicate key detection - Hex/Octal/Binary integers: 0xDEADBEEF, 0o755, 0b11010110 - Dotted keys in standalone key-value pairs: a.b.c = "value" - Native datetime parsing (currently returns ISO 8601 strings)
Planned for v0.4.0+: - Writer/serialiser functionality
π§ͺ Testing
All 79 tests passing: - 25 lexer tests - 10 parser tests - 4 real-world file tests - 5 fixture tests - 14 array tests - 13 inline table tests - 8 table header tests
Run tests yourself:
git clone https://github.com/databooth/mojo-toml
cd mojo-toml
pixi install
pixi run test-allπ Documentation
- README.md - Complete usage guide
- CHANGELOG.md - Detailed change history
- docs/TABLE_HEADERS_BLOCKER.md - Technical explanation of flat key limitation
- TOML 1.0 Spec - Official specification
π§ Compatibility
- Mojo Version: Tested with Mojo 2025/2026 (via pixi)
- Platforms: macOS (Apple Silicon), Linux
- Python: Zero dependencies for runtime
β οΈ .mojopkg Compatibility Note: The compiled package is built with the Mojo version shown in the build artifacts. It may not work with different Mojo versions. Source installation is recommended for maximum compatibility.
πΊοΈ Roadmap
v0.3.0 (Next) - TOML 1.0 Compliance
- Array of tables:
[[array]] - Duplicate key detection
- Hex/Octal/Binary integers
- Dotted keys in key-value pairs
- Native datetime types
- Enhanced error messages
v0.4.0
- SIMD optimisations
- Performance benchmarks
- Advanced optimizations
π Acknowledgements
Built with inspiration from: - Python tomli - Reference implementation - mojo-dotenv - Proven parser patterns - TOML Specification - Excellent config format by Tom Preston-Werner
π¬ Feedback & Support
- Issues: GitHub Issues
- Discussions: Modular Discord - #mojo channel
- Sponsor: This project is sponsored by DataBooth
Full Changelog: See CHANGELOG.md for complete details.