Incorrect handling of nested modules
I think menhir does not generate valid code when a nested module is used in the .mly
source. More eloquently, I have the following project structure:
.
├── _tags
└── src
├── foo.ml
├── main.ml
└── parser.mly
With:
- parser.mly:
%{
open Foo
%}
%token EOF
%start eof
%type <Bar.bar> eof
%%
eof: EOF { Bar.n }
- foo.ml
module Bar = struct
type bar = int
let n = 42
end
- main.ml
open Parser
let () = ()
- _tags:
true: use_menhir
<src>: include
When I compile using ocamlbuild main.byte
, I get the following error:
+ ~/.opam/4.05.0/bin/ocamlc.opt -c -I src -o src/parser.cmi src/parser.mli
File "src/parser.mli", line 13, characters 55-62:
Error: Unbound module Bar
Indeed the generated parser.mli
file looks like:
(* The type of tokens. *)
type token =
| EOF
(* This exception is raised by the monolithic API functions. *)
exception Error
(* The monolithic API. *)
val eof: (Lexing.lexbuf -> token) -> Lexing.lexbuf -> (Bar.bar)
Foo
being never opened, Bar.bar
does not make sense here, hence the compile error.
I am using:
- ocamlc version
4.05.0
- ocamlbuild version
0.11.0
- menhir version
20170712
Am I doing something wrong or is it an actual bug?