I am working on a port of ungrammar to ocaml. It is a DSL for specifying concrete syntax trees. Ungrammar is just a parser that produces “grammars” which are lists of nodes and tokens, whatever those are.
The original setup is like this:
Running cargo xtask codegen first parses a rust grammar and generates file based on the grammar in the working directory. This generated rust code defines an API for working with rust syntax, and this API is used throughout the rest of the codebase.
So far, I have a working ungrammar parser and would now like to use ppxlib to generate some ocaml. After struggling a bit with writing a preprocessor, I am now wondering how I can best use ppxlib to create a program that generates an ocaml file. I just want to generate some code from an ocaml value, I don’t really care for transforming ocaml ASTs through extension nodes.
Ideally I would like a dune rule which generates the code in my working tree, not somewhere deep in the _build folder. This dune rule would specify the dependency on the specific grammar to be parsed.