Using batteries in a .mly file with ocamlbuild

I have a project with OCaml.ml files and a Menhir.mly file. I use ocamlbuild to compile the project.

My _tags file contains this single line:

true: use_menhir, package(batteries) 

Everything works well, except when I want to use Batteries in a .mly file. If I open Batteries ;; between %{ and %} in my .mly file, I get a "Error: Unbound Module Batteries" message when ocamlbuild is called.

It seems that when ocamlbuild calls menhir, like this:

 /usr/bin/menhir --ocamlc '/usr/bin/ocamlfind ocamlc' --infer parser.mly 

he forgets to add -package batteries (or something similar) to the --ocamlc option for menhir.

How can i fix this? Maybe a special rule for my .mly file in my _tags file might help. Or is it ocamlbuild error?

+4
source share
2 answers

This is assumed to be fixed in recent versions of OCaml (see http://caml.inria.fr/mantis/view.php?id=5763 ). Which version are you using?

+5
source

Before the next version of OCaml, there is a good working environment described in Jonathan's link. If your .mly file is named foo.mly , you can define a foo.mlypack file with the following contents:

 Foo 

Then foo.ml will use the .mlypack file (originally designed to support the menhir modular grammar combining function), which correctly passes compilation options to the --infer parameter, since .mlypack compilation was fixed a long time ago.

+5
source

Source: https://habr.com/ru/post/1497593/


All Articles