When using Menhir it is possible to split the grammar specification into multiple files, as described here.
Is it possible to make the same thing with Ocamllex definitions ?
I’m currently working on a small DSL with is parameterized on the kind of embedded (arithmetic) expressions. This parameterization is nicely supported by the Menhir “split” facility (one mly file for the DSL grammar, and another for the expression grammar).
But, currently, i still have to put all the lexer definitions in the same .mll file, which obviously breaks down modularity.
A solution could be to used stacked parsers/lexers, as described here, for example in this post, but in my case, there’s no specific delimiters for “enclosed” expressions and therefore switching btw lexers and parsers is problematic.
Another solution could be the textually merge .mll specs before submitting the result to ocamllex but this is really ugly
Anyway, this is really a workaround. Having to put all lexer definitions in the same file - either by hand or using some pre-processing tool - significantly limits the modularity provided by Menhir, doesn’t it ?
Ok, thanks for the idea and example !
I didn’t know cppo and it seems to open many opportunities.
Probably little. But it will make integration with Menhir simpler. It could also allow some semantic checking (e.g. that the same rule is not defined twice) that a purely textual inclusion mechanism cannot handle (just as th eMenhir merging mechanism can detect token redefinition).
I only use Makefiles, so don’t know the answer, but I remember that somebody else had a similar problem (getting some file to be copied-over to the build directory) and there was a way to specify it in dune. Wish I could remember what it was, or what the title of the post was. Maybe someone here will remember …