An implementation of the Jirai Data Language parser and deserializer in Zig.
- Zig 100%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| src | ||
| .gitignore | ||
| build.zig | ||
| build.zig.zon | ||
| LICENSE | ||
| README.markdown | ||
| zlint.json | ||
JMU.ZIG
An implementation of the Jirai Data Language parser and deserializer in Zig.
ABOUT
This repository contains the Zig source code for a parser and deserializer for the Jirai Data Language. This library is a port of the Rust library by the same name.
INSTALLATION
This Zig library uses Zig version 0.14.0.
To add this library to your project, use the following command:
zig fetch --save git+https://source.alyxshang.boo/alyxshang/jmu.zig.git#v.0.1.0
The following module must also be declared in your project's build.zig:
const jmu_dep = b.dependency(
"jmu",
.{
.target = target,
.optimize = optimize,
}
);
your_main_module.root_module.addImport("jmu", jmu_dep.module("jmu"));
your_main_module is the module you want to add JMU.ZIG to.
USAGE
You would use this library and JMU together in the way outlined in the code snippet below:
const std = @import("std");
const jmu = @import("jmu");
const Command = struct {
name: [*:0]const u8,
command: [*:0]const u8,
pub fn deinit(
self: *const Command,
allocator: std.mem.Allocator
) void {
allocator.free(std.mem.span(self.name));
allocator.free(std.mem.span(self.command));
}
};
const TestSubStruct = struct {
fav_characters: i64,
is_goth: bool,
};
const TestStruct = struct {
name: [*:0]const u8,
age: i64,
gpa: f64,
is_political: bool,
likes_cake: bool,
imp_nums: std.ArrayList(i64),
float_nums: std.ArrayList(f64),
hobbies: std.ArrayList([*:0]const u8),
truth_table: std.ArrayList(bool),
sub_info: TestSubStruct,
misc_list: std.ArrayList(Command),
pub fn deinit(
self: *TestStruct,
allocator: std.mem.Allocator
) void {
allocator.free(std.mem.span(self.name));
self.imp_nums.deinit();
self.float_nums.deinit();
self.truth_table.deinit();
for (self.hobbies.items) |hobby|{
allocator.free(std.mem.span(hobby));
}
self.hobbies.deinit();
for (self.misc_list.items) |item| {
item.deinit(allocator);
}
self.misc_list.deinit();
}
};
pub fn main() !void {
const test_str: [*:0]const u8 =
\\"name" >~< "Alyx"
\\"age" >~< 2026
\\"gpa" >~< 1.0
\\"is_political" >~< false
\\"likes_cake" >~< true
\\"imp_nums" >~< [45, 46, 47]
\\"float_nums" >~< [34.5, 12.3, 67.8]
\\"hobbies" >~< ["art", "code", "reading"]
\\"truth_table" >~< [true, false, true, true]
\\"sub_info" >~< |
\\ "fav_characters" >~< 3
\\ "is_goth" >~< true
\\|
\\"misc_list" >~< [
\\ |
\\ "name" >~< "build"
\\ "command" >~< "echo"
\\ |,
\\ |
\\ "name" >~< "clean"
\\ "command" >~< "echo"
\\ |
\\]
;
var ms: TestStruct = try from.fromStr(
TestStruct,
std.testing.allocator,
test_str
);
defer ms.deinit(std.testing.allocator);
std.debug.print("{any}\n", .{deserialized});
}
More information on the entities inside this library
can be obtained by cloning this repository and running the zig build docs
command from the repository's root.
CHANGELOG
Version 0.1.0
- Initial release.
- Upload to Forgejo.
NOTE
- JMU.ZIG by Alyx Shang.
- Licensed under the FSL v1.