dune menhir / ocamllex generation error in CI
dune runs menhir or ocamllex to generate parser/lexer code before compiling. A grammar conflict or a lexer syntax error stops generation, so the produced .ml never exists and the build fails.
What this error means
dune build fails inside a menhir or ocamllex rule with "Warning: N states have conflicts", "menhir: ... failed", or an ocamllex parse error, before the OCaml compiler runs.
File "src/parser.mly", line 42:
Error: 3 states have shift/reduce conflicts.
menhir: 1 error(s) encounteredCommon causes
Grammar conflicts treated as errors
menhir reports shift/reduce or reduce/reduce conflicts; with strict settings these fail the build rather than warn.
A lexer or grammar syntax error
An ocamllex rule or menhir declaration has a syntax mistake, so generation cannot produce valid OCaml.
How to fix it
Resolve grammar conflicts
- Run menhir with
--explainto get a conflict report. - Add precedence declarations or refactor the ambiguous rules.
- Rebuild until menhir reports no conflicts.
menhir --explain src/parser.mlyFix the lexer/grammar syntax
Correct the ocamllex or menhir syntax the error points at, then let dune regenerate.
dune build src/parser.ml src/lexer.mlHow to prevent it
- Keep grammars conflict-free with explicit precedence.
- Run
menhir --explainlocally before pushing grammar changes. - Regenerate parser/lexer code as part of local builds.