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.
plib
core module, parser generatorabnf
abnf file parser/serializer,ABNF
structure generator, generate itselftoml
toml file parser/serializer, follow toml v1.0.0, passed alltoml-test
tests
Use 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 <mod_name> 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:
- Add
src/raw/json.abnf
, which contains json's abnf definition. - Run
zig build -Dstep=gen_abnf -Dname=json
to generatesrc/gen/json.zig
. - Modify
zig.build
(andzig.build.zong
if so desired) to build ajson
module. - Add
src/mod/json/root.zig
, which is the root source file ofjson
module. Seesrc/mod/toml/root.zig
for example. - If you are using vscode, you might also want to modify
.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");