Luna1996/plib
collection of multiple modules, which includes a parser generator and parsers generated by it.
plib (short for parser library) is a collection of multiple modules, which includes a parser generator and parsers generated by it.
plib takes a pre-generated ABNF structure as input to produce a parser.parser will take raw text as input to generate the AST of it.
NOTE Contribution is much welcomed, but beware that currently this is just a personal project for fun.
WARNING Lack of comments and documents. You need to dig into the bare code to use and knew the logic behind the library.
plibabnfABNF structure generator, generate itselftomltoml-test testsUse following command to generate the ABNF structure that defines ABNF syntax.
zig build -Dstep=gen_abnf -Dname=file_name
This command runs gen_abnf.zig, takes src/raw/<file_name>.abnf and outputs src/gen/<file_name>.zig.
Use following command to test module.
zig build -Dstep=test -Dname=mod_name
To test the toml module against toml-test, first make sure toml-test is on your PATH, then
zig build -Dstep=toml_test
Currently all tests is passed.
toml-test v2024-05-31 [C:\repo\repo.zig\plib\zig-out\bin\toml_encoder.exe]: using embedded tests
encoder tests: 182 passed, 0 failed
toml-test v2024-05-31 [C:\repo\repo.zig\plib\zig-out\bin\toml_decoder.exe]: using embedded tests
valid tests: 182 passed, 0 failed
invalid tests: 371 passed, 0 failed
Suppose you want to add a json parser (maybe not since it's included in std lib). You should:
src/raw/json.abnf, which contains json's abnf definition.zig build -Dstep=gen_abnf -Dname=json to generate src/gen/json.zig.zig.build (and zig.build.zong if so desired) to build a json module.src/mod/json/root.zig, which is the root source file of json module. See src/mod/toml/root.zig for example..vscode/tasks.json.In your build.zig.zon add:
.dependencies = .{
.plib = .{
.url = "https://github.com/Luna1996/abnf/archive/main.tar.gz",
},
},
In your build.zig add:
const plib_dep = b.dependency("plib", .{.toml = true});
const plib_mod = plib_dep.module("plib");
const toml_mod = plib_dep.module("toml");
main_mod.addImport("plib", plib);
main_mod.addImport("plib", toml);
In your project add:
const plib = @import("plib");
const toml = @import("toml");