Is it possible to let several lexers share same ident definitions?

谁说胖子不能爱 提交于 2019-12-11 23:25:42

问题


I have several lexers: lexer_1.mll, lexer_2.mll, ...

Some definitions of ident (let ident = regexp) are common and repeated in these files. For instance, the definition of INTEGER, FLOAT, ...

Does anyone know if it is possible to define them the once for all somewhere, and let the .mll files call it?


回答1:


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.



来源:https://stackoverflow.com/questions/19426619/is-it-possible-to-let-several-lexers-share-same-ident-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!