Using Batteries in .mly file with ocamlbuild

655 views Asked by At

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 the .mly file. If I open Batteries ;; between %{ and %} in my .mly file, I get "Error: Unbound module Batteries" when calling ocamlbuild.

It seems that when ocamlbuild is calling menhir, like this:

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

it forgets to add -package batteries (or something equivalent) in the --ocamlc option of menhir.

How can I fix that? Maybe a special rule for my .mly file in my _tags file could help? Or is it a ocamlbuild bug?

2

There are 2 answers

2
Jonathan Protzenko On BEST ANSWER

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

1
gasche On

Before the next OCaml release, there is a good work-around described in the link given by Jonathan. If your .mly file is named foo.mly, you can define a foo.mlypack file with the following content:

Foo

Producing foo.ml will then use the .mlypack file (originally meant to support menhir's modular grammar combination feature), which will correctly pass the compilation options to the --infer parameter -- because .mlypack compilation was fixed long ago.