4

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?

p4bl0
  • 3,846
  • 1
  • 22
  • 21

2 Answers2

5

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

Jonathan Protzenko
  • 1,709
  • 8
  • 13
  • I'm using OCaml 4.00.1, Batteries 2.1, and ocamlbuild 4.00.1. These are the most recent released versions. I don't want to be working with the SVN version so I guess I'm stuck with the bug for now. Thanks for clearing out the situation. – p4bl0 Aug 17 '13 at 17:21
  • Yes. With svn version: `menhir --explain --infer -la 1 --table --ocamlc 'ocamlfind ocamlc -I +ocamlbuild -g -annot -bin-annot -strict-sequence -bin-annot -package yojson -package menhirLib -package ulex -package pprint -package fix -I parsing -I utils -I typing -I interpreter -I lib -I compiler -I mezzolib -I tests/unit' --infer parsing/grammar.mly ` with 4.00.1: `+ menhir --explain --infer -la 1 --table --ocamlc '/home/jonathan/.opam/4.00.1/bin/ocamlfind ocamlc -I parsing -I utils -I typing -I interpreter -I lib -I compiler -I mezzolib -I tests/unit' --infer parsing/grammar.mly ` – Jonathan Protzenko Aug 17 '13 at 22:11
5

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.

gasche
  • 31,259
  • 3
  • 78
  • 100