Generate dump/explain files of Menhir when using ocamlbuild
Asked Answered
A

1

7

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?

Alps answered 3/5, 2015 at 8:1 Comment(0)
A
3

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.

Alps answered 27/5, 2015 at 5:7 Comment(1)
sometimes I wonder how ocamlbuild can be so poor in documentation yet so rich in details. Also, how community myocamlbuild modules didn't achieve to be a thing... This could be the best place to put this kind of docSplendor

© 2022 - 2024 — McMap. All rights reserved.