Generate a parser enabling incremental API and inspection API

This question is indeed related to the interaction of menhir and build systems. Precisely, the inspection API (--inspection) requires the type information of .mly (including its semantic actions) to be known. I chose to directly work on parse_e.mly rather than unitActionsParser_e.mly, and followed the approach of “Obtaining OCaml type information without calling the OCaml compiler”:

  • menhir --explain --inspection --table --dump --infer-write-query mockfile.ml parser_e.mly to generate mockfile.ml

  • ocamlfind ocamlc -I lib -package sedlex -package menhirLib -i mockfile.ml > sigfile to generate sigfile. Note that -I lib refers to the directory of external modules, their .cm[io] files should be ready to use.

  • menhir --explain --inspection --table --dump --infer-read-reply sigfile parser_e.mly to generate especially parser_e.ml, parser_e.mli, .conflicts and automaton.

As a result, parser_e.ml contains more type information and the inspection API is in Parser_e.MenhirInterpreter.