caiocdcs/maml-zig
Zig MAML Parser
A minimal, spec-compliant MAML (Minimal Abstract Markup Language) parser implementation in Zig.
MAML is a minimal configuration format designed to be easily readable by humans and easily parsed by machines. Think of it as a simpler alternative to JSON, TOML, or YAML.
Learn more at: https://maml.dev/spec/v0.1
Clone the repository:
git clone https://github.com/caiocdcs/maml-zig.git
cd maml-zig
Build:
zig build
Using build.zig.zon (recommended)
Add to your build.zig.zon:
.{
.name = "my-project",
.version = "0.1.0",
.dependencies = .{
.maml_zig = .{
.url = "https://github.com/caiocdcs/maml-zig/archive/refs/heads/main.tar.gz",
// Run 'zig fetch' to get the hash
.hash = "1220abcdef...",
},
},
}
Then in your build.zig:
const maml_zig = b.dependency("maml_zig", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("maml_zig", maml_zig.module("maml_zig"));
const std = @import("std");
const maml = @import("maml_zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const source =
\\{
\\ name: "My App"
\\ version: 1
\\ enabled: true
\\}
;
var value = try maml.parse(allocator, source);
defer value.deinit(allocator);
if (value == .object) {
const name = value.object.get("name").?.string;
std.debug.print("Name: {s}\n", .{name});
}
}
Parse a MAML file:
# Build
zig build
# Parse a file
./zig-out/bin/maml_zig example.maml
Or run directly:
zig build run -- example.maml
The parser returns a Value union with these variants:
object - Key-value pairs (std.StringHashMap)array - List of values (std.ArrayList)string - UTF-8 stringinteger - 64-bit signed integerfloat - 64-bit floating pointboolean - true or falsenull_value - nullRun the example:
zig build run -- example.maml
Run all tests:
zig build test --summary all
MAML supports:
{ key: "value" }[1, 2, 3]"hello""""multiline text"""42, 3.14, 1e-10true, falsenull# commentSee example.maml for a complete example.
For full syntax details, visit: https://maml.dev/spec/v0.1
The parser returns descriptive errors:
UnterminatedString - Missing closing quoteUnterminatedRawString - Missing closing """InvalidEscape - Invalid escape sequenceUnexpectedCharacter - Invalid characterUnexpectedToken - Token in wrong contextExpectedColon - Missing : in objectDuplicateKey - Object has duplicate keysMIT License.