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 ?
Oh, I didn’t mean that ocamllex would accept them, but rather, that you could just use cppo to perform the inclusion. I tried it just now on the OCaml compiler’s lexer:
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).
Error: File "lexer.cppo.mll", line 39, characters 0-23
Error: Cannot find included file "expr_kw.inc"
I guess it’s because the included file expr_kw.inc is only present in the source tree (src/bin/) and not in the build repository (_build/default/src/bin/). But i cannot have dune automatically copy it
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 …