This is a PEG parser generator, it generates rust code from an abstract description. You can find the self-hosted grammar of the gnag language here.
A vscode extensions and an LSP server are planned, and were at one point implemented, but are currently thoroughly broken due to an ongoing rewrite.
The rewrite is almost done (famous last words) and will improve the following:
-
Propagate source spans through the whole compilations.
-
Keep the parsing expression in a structured form all the way through.
The previous version converted it to a graph, then did optimizations, then structured it again. This was really complicated and resulted in some loss of control over the shape of the generated code.
-
Generally learn from previous experience and make this version better.
The docs/ directory contains a grammar describing simple math expressions. There are debug dumps of various stages of the grammar compilation:
- expression.gng - the grammar itself
- expression.cst - the concrete syntax tree of the grammar file (trivia tokens are excluded from the debug dump)
- expression.ast - the abstract form of the grammar, constructs like pratt recursion are lowered to a recursive rule
- expression.code.rs - the generated rust-like code, I need to write some passes to clean it up
- grammar.gng - the self hosted grammar of the grammar language
- gnag-parser/src/lib.rs - currently used to parse the grammar language, it was generated by the version before the rewrite and has since been modified to keep up with the runtime.
- gnag-runtime/ - the parser runtime which is driven by the parser to construct the CST.
- code-render-macro/ - a rust procedural macro, similar to the
synlibrary. It allows to efficiently compose interpolated text, it is used to generate the parser code.