Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 580
Seungcheol Jung Avatar asked May 03 '15 08:05

Seungcheol Jung


1 Answers

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.

like image 67
Seungcheol Jung Avatar answered Oct 21 '22 04:10

Seungcheol Jung