Using Base (or other stdlib replacements) with Menhir

I’ve been using Menhir a bit recently with Jane Street’s libraries. With Core_kernel, things work as I want them to. However, if I instead use Base, I run into the following dilemma:

  1. If I open Base at the top of a .mly file, I can use Base throughout the code that I write. However, having Base opened breaks things in the generated code, because Menhir uses functions like Printf.printf that no longer exist. I can get around this with stuff like module Printf = struct include Printf let fprintf = Stdio.Out_channel.fprintf, but that’s ugly and requires manually catching the missing functions.

  2. I can instead just open Base locally in the expressions where I actually want to use it, but having let open Base in spread around is a bit clunky, given that Base is supposed to be functioning as a standard library.

I’m curious to know if anyone else has dealt with this issue, and how they’ve solved it.

1 Like

This won’t help you directly, but I suggest raising an issue wherever Menhir tracks bugs, because generated code should always go through a uniquely named module (e.g. MenhirRuntime) to access the external things so that it at least gets some semblance of hygiene.

Is this issue already raised? According to Opam, Menhir uses an email address as a tracker, so one can’t know: