Skip to content

Commit 3d71583

Browse files
Mjboothauswarp-agentyetalit
authored
Add mojo-toml v0.5.1 - Native TOML parser & writer (#196)
* Add mojo-toml v0.3.0 - Native TOML parser for Mojo Package: mojo-toml v0.3.0 A native TOML 1.0 parser for Mojo with zero Python dependencies. Features: - Complete TOML 1.0 syntax support - 96 comprehensive tests ensuring reliability - Nested tables, dotted keys, duplicate detection - Clear error messages with line/column context - Performance: 26μs for simple parses, 2ms for real files Repository: - GitHub: https://github.com/DataBooth/mojo-toml - Release: https://github.com/DataBooth/mojo-toml/releases/tag/v0.3.0 - License: MIT Testing: Package includes test_package.mojo which validates: - Simple key-value parsing - Integer and array parsing - Nested table structures - Dotted key functionality All 96 tests pass in the source repository. Sponsored by DataBooth (https://www.databooth.com.au/posts/mojo) * Update mojo-toml to v0.5.0 Updates mojo-toml from v0.3.0 to v0.5.0 with full TOML 1.0 compliance and partial TOML 1.1 support. Major changes since v0.3.0: - Complete TOML 1.0 specification (array-of-tables, alt number bases) - Partial TOML 1.1 support (\xHH and \e escapes) - 168 tests (up from 96) - Comprehensive benchmarking system - Pre-commit hooks fixed - TOML writer with round-trip fidelity Release: https://github.com/DataBooth/mojo-toml/releases/tag/v0.5.0 Co-Authored-By: Warp <agent@warp.dev> * Add package image for builds.modular.com display per reviewer request * Bump version to 0.5.1 with CodeQL and package image * Fix mojo-toml recipe: update tag to v0.5.1 and license to Apache-2.0 - Update source tag from v0.5.0 to v0.5.1 - Update license from MIT to Apache-2.0 (matches upstream change) Co-Authored-By: Warp <agent@warp.dev> * Standardize mojo-toml to use mojo_version context with 0.25.7 - Add context with version and mojo_version variables - Change from 'mojo >=25.1' to 'mojo-compiler =0.25.7' - Use pin_compatible() for runtime dependency Co-Authored-By: Warp <agent@warp.dev> * Fix mojo-toml recipe schema errors - Change 'test:' to 'tests:' with script block - Change 'doc_url' to 'documentation' - Change 'dev_url' to 'repository' Fixes recipe parser errors per modular-community schema. Co-Authored-By: Warp <agent@warp.dev> * Update mojo-toml recipe to Mojo 0.26.1 Co-Authored-By: Warp <agent@warp.dev> --------- Co-authored-by: Warp <agent@warp.dev> Co-authored-by: Tiyagora <98420273+yetalit@users.noreply.github.com>
1 parent d2e664a commit 3d71583

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

recipes/mojo-toml/image.png

5.88 KB
Loading

recipes/mojo-toml/recipe.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
context:
2+
version: 0.5.1
3+
mojo_version: "=0.26.1"
4+
5+
package:
6+
name: mojo-toml
7+
version: ${{ version }}
8+
9+
source:
10+
git: https://github.com/DataBooth/mojo-toml.git
11+
tag: v0.5.1
12+
13+
build:
14+
number: 0
15+
script:
16+
- mkdir -p $PREFIX/lib/mojo/toml
17+
- cp -r src/toml/* $PREFIX/lib/mojo/toml/
18+
19+
requirements:
20+
build:
21+
- mojo-compiler ${{ mojo_version }}
22+
host:
23+
- mojo-compiler ${{ mojo_version }}
24+
run:
25+
- ${{ pin_compatible('mojo-compiler') }}
26+
27+
tests:
28+
- script:
29+
- test -f $PREFIX/lib/mojo/toml/__init__.mojo
30+
- test -f $PREFIX/lib/mojo/toml/lexer.mojo
31+
- test -f $PREFIX/lib/mojo/toml/parser.mojo
32+
- test -f $PREFIX/lib/mojo/toml/writer.mojo
33+
34+
about:
35+
homepage: https://github.com/DataBooth/mojo-toml
36+
license: Apache-2.0
37+
license_file: LICENSE
38+
summary: Native TOML 1.0 parser and writer for Mojo - Complete + Partial 1.1 🔥
39+
description: |
40+
mojo-toml is a native TOML 1.0 parser and writer for Mojo, enabling
41+
fast and efficient parsing and writing of TOML configuration files with zero
42+
Python dependencies.
43+
44+
Features:
45+
- Complete TOML 1.0 specification support
46+
- Array of tables [[section]] syntax
47+
- Alternative number bases (hex 0xDEAD, octal 0o755, binary 0b1101)
48+
- Partial TOML 1.1: \xHH and \e escape sequences
49+
- TOML writer with full round-trip fidelity
50+
- Nested table structures with proper Dict navigation
51+
- Dotted keys for creating nested structures
52+
- Duplicate key detection
53+
- Clear error messages with line/column context
54+
- 168 comprehensive tests (127 parser + 41 writer)
55+
- Performance: 24μs for simple parses, 2ms for real-world files
56+
- Comprehensive benchmark system
57+
58+
Perfect for configuration files, build systems, and any Mojo application
59+
needing structured configuration.
60+
documentation: https://github.com/DataBooth/mojo-toml/blob/main/README.md
61+
repository: https://github.com/DataBooth/mojo-toml
62+
63+
extra:
64+
recipe-maintainers:
65+
- mjboothaus
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Test file for mojo-toml package installation.
2+
3+
This test verifies that mojo-toml is properly installed and can parse TOML.
4+
"""
5+
6+
from toml import parse
7+
8+
9+
fn main() raises:
10+
"""Test basic TOML parsing functionality."""
11+
12+
print("Testing mojo-toml package installation...")
13+
14+
# Test 1: Simple key-value parsing
15+
var config1 = parse('name = "mojo-toml"')
16+
var name = config1["name"].as_string()
17+
if name != "mojo-toml":
18+
raise Error("Test failed: Expected 'mojo-toml', got: " + name)
19+
print("✓ Test 1 passed: Simple key-value")
20+
21+
# Test 2: Integer parsing
22+
var config2 = parse('port = 8080')
23+
var port = config2["port"].as_int()
24+
if port != 8080:
25+
raise Error("Test failed: Expected 8080, got: " + String(port))
26+
print("✓ Test 2 passed: Integer parsing")
27+
28+
# Test 3: Array parsing
29+
var config3 = parse('items = [1, 2, 3]')
30+
var items = config3["items"].as_array()
31+
if len(items) != 3:
32+
raise Error("Test failed: Expected 3 items, got: " + String(len(items)))
33+
print("✓ Test 3 passed: Array parsing")
34+
35+
# Test 4: Nested table parsing
36+
var config4 = parse('[database]\nhost = "localhost"\nport = 5432')
37+
var db = config4["database"].as_table()
38+
var host = db["host"].as_string()
39+
if host != "localhost":
40+
raise Error("Test failed: Expected 'localhost', got: " + host)
41+
print("✓ Test 4 passed: Nested tables")
42+
43+
# Test 5: Dotted keys
44+
var config5 = parse('a.b.c = "nested"')
45+
var a_table = config5["a"].as_table()
46+
var b_table = a_table["b"].as_table()
47+
var c_value = b_table["c"].as_string()
48+
if c_value != "nested":
49+
raise Error("Test failed: Expected 'nested', got: " + c_value)
50+
print("✓ Test 5 passed: Dotted keys")
51+
52+
print()
53+
print("✅ All tests passed! mojo-toml is working correctly.")
54+
print("Package version: 0.3.0")

0 commit comments

Comments
 (0)