Fetching contributors…
Cannot retrieve contributors at this time
74 lines (47 sloc) 1.62 KB


To use menhir in a dune project, the language version should be selected in the dune-project file. For example:

(using menhir 2.0)

This will enable support for menhir stanzas in the current project. If the language version is absent, dune will automatically add this line with the latest menhir version to the project file once a menhir stanza is used anywhere.

Basic Usage

The basic form for defining menhir parsers (analogous to ocamlyacc) is:

 (modules <parser1> <parser2> ...))

Modular Menhir

Modular parsers can be defined by adding a merge_into field. This correspond to the --base command line option of menhir. With this option, a single parser named base_name is generated.

 (merge_into <base_name>)
 (modules <parser1> <parser2> ...))


Extra flags can be passed to menhir using the flags flag:

 (flags <option1> <option2> ...)
 (modules <parser1> <parser2> ...))

--infer mode

Menhir language 2.0 automatically enables using menhir with type inference. This ability can also be manually controlled with the infer field manually.

  (infer false)
  (modules <parser1> <parser2> ...))

cmly targets

Menhir supports writing the grammar and automaton to .cmly file. Therefore, if this is flag is passed to menhir, dune will know to introduce a .cmly target for the module.