Is it possible to make Menhir generate a functor? Or something to that effect?
For a small example, say you have a family of languages that share the same structure except for the value type and keywords. Say I have a module signature:
module type M = sig type value_type type keywordend
with some AST functor:
module AST (M : M) = struct type t = ... ...end
I can define multiple AST variants with different types and keywords by instantiating them with different M
. e.g. AST1 = AST(M1)
, AST2 = AST(M2)
, etc.
If I want a Parser for AST(M).t
, however, I am limited to making a different parser for each AST1
, AST2
, etc, unless there's a way to make the parser parametric on M
.
I can alternatively define an intersection AST that can then be converted into each variant. But this requires traversing every AST after parsing, so I was hoping Menhir perhaps can do it in a single step.