I'm afraid there's no "pure OCaml" solution, as ident
seems to be systematically inlined by ocamllex
. You can still put your regexp definition in a file, and use cpp
(or any other C pre-processor) to #include
it wherever needed though. This is of course an abuse of cpp
, as you're not feeding it with .c
file, but you wouldn't be the first one to do that.
As a matter of fact, I've just come across cppo, a cpp-like utility targetting OCaml programs, that you might find useful.