Generate dump/explain files of Menhir when using ocamlbuild

I discovered that Menhir provides --dump and --explain options and it helps debugging a lot. But how can I enable these options under ocamlbuild so that Menhir always generates dump files at compile time?

I tried to write myocamlbuild file handling custom tag menhir_dump like the below:

... snip ...
(* OASIS_STOP *)

Ocamlbuild_plugin.dispatch (
  MyOCamlbuildBase.dispatch_combine [
    (function
      | After_rules ->
          flag ["menhir_dump"] (S [A "--dump"; A "--explain"])

      | _ -> ()
    );
    dispatch_default
  ]
)

But when it compiles, the options are inserted into sub-command and the compilation fails during ocamlc stage.

menhir --dump --explain --raw-depend --ocamldep 'ocamlfind ocamldep -modules' src/parser.mly > src/parser.mly.depends
menhir --ocamlc 'ocamlfind ocamlc -g -annot -bin-annot --dump --explain -I src -package cmdliner -package menhirLib -I src' --dump --explain --infer src/parser.mly
+ menhir --ocamlc 'ocamlfind ocamlc -g -annot -bin-annot --dump --explain -I src -package cmdliner -package menhirLib -I src' --dump --explain --infer src/parser.mly
                                                         ^^^^^^^^^^^^^^^^
ocamlc: unknown option '--dump'.
...snip...

Any suggestions?


I answer it myself.

There is, of course, a built-in ocamlbuild option for this. Just put explain in _tags like the below.

true: use_menhir, explain

You may lookup built-in options using ocamlbuild -documentation .

链接地址: http://www.djcxy.com/p/26038.html

上一篇: 如何使用Css3转换创建站立式3D文字效果

下一篇: 使用ocamlbuild时生成Menhir的dump / explain文件