# \#menhir

**URL:** https://discuss.ocaml.org/tag/menhir/155.md

[Latest](https://discuss.ocaml.org/latest.md) · [Categories](https://discuss.ocaml.org/categories.md) · [Tags](https://discuss.ocaml.org/tags.md)

---

## [Dune build @doc with menhir generated files](https://discuss.ocaml.org/t/dune-build-doc-with-menhir-generated-files/18337)

<div class="topic-metadata">

**Author:** [@Nyavlys](https://discuss.ocaml.org/u/Nyavlys)\
**Replies:** 3\
**Last updated:** [July 14, 2026, 9:47am UTC](https://discuss.ocaml.org/t/dune-build-doc-with-menhir-generated-files/18337 "2026-07-14T09:47:14Z")

</div>

Hi, After moving from menhir.20250912 to more recent versions, I have the following error message from odocwhen running dune build @doc Error: While resolving the expansion of include at File "src/scripting/tableParser…

---

## [LRgrep 0.9: Better syntax errors for OCaml and Menhir](https://discuss.ocaml.org/t/lrgrep-0-9-better-syntax-errors-for-ocaml-and-menhir/18286)

<div class="topic-metadata">

**Author:** [@let-def](https://discuss.ocaml.org/u/let-def)\
**Replies:** 0\
**Last updated:** [June 24, 2026, 4:50am UTC](https://discuss.ocaml.org/t/lrgrep-0-9-better-syntax-errors-for-ocaml-and-menhir/18286 "2026-06-24T04:50:54Z")

</div>

Hi everyone, I’ve just released LRgrep 0.9, a tool to customize the error messages of Menhir-generated LR parsers by reasoning about failure paths. The goal is to move from generic “Syntax error at line X” messages to …

---

## [Catching a Menhir-generated exception](https://discuss.ocaml.org/t/catching-a-menhir-generated-exception/14931)

<div class="topic-metadata">

**Author:** [@mvanier](https://discuss.ocaml.org/u/mvanier)\
**Replies:** 5\
**Last updated:** [June 30, 2025, 1:50pm UTC](https://discuss.ocaml.org/t/catching-a-menhir-generated-exception/14931 "2025-06-30T13:50:58Z")

</div>

I’m learning how to use Menhir for parsing a language, and so far it’s been great except for error handling. I have a few questions. I’m working with Menhir version 20231231. First, the manual seems to imply that “new…

---

## [Need feedback on my basic unit test](https://discuss.ocaml.org/t/need-feedback-on-my-basic-unit-test/16706)

<div class="topic-metadata">

**Author:** [@andreamancuso](https://discuss.ocaml.org/u/andreamancuso)\
**Replies:** 10\
**Last updated:** [May 27, 2025, 6:03pm UTC](https://discuss.ocaml.org/t/need-feedback-on-my-basic-unit-test/16706 "2025-05-27T18:03:51Z")

</div>

open Rezn.Frontend open Yojson.Basic let%expect\_test "parsing a minimal pod" = let source = {| pod "x" { image = "nginx" } |} in let prog = parse\_string source in let json = Rezn.Codegen.program\_to\_json prog in …

---

## [Dune: Update vs create target](https://discuss.ocaml.org/t/dune-update-vs-create-target/16692)

<div class="topic-metadata">

**Author:** [@joelreymont](https://discuss.ocaml.org/u/joelreymont)\
**Replies:** 3\
**Last updated:** [May 23, 2025, 2:13pm UTC](https://discuss.ocaml.org/t/dune-update-vs-create-target/16692 "2025-05-23T14:13:13Z")

</div>

I’d like for dune to Create the Menhir parser.messages file it it does not exist and Update the parser.messages file if it does and my parser.mly has changed. I defined two rules (rule (targets parser.messages) (mo…

---

## [Juxtaposition in Menhir](https://discuss.ocaml.org/t/juxtaposition-in-menhir/9782)

<div class="topic-metadata">

**Author:** [@ghulette](https://discuss.ocaml.org/u/ghulette)\
**Replies:** 7\
**Last updated:** [March 27, 2025, 5:44pm UTC](https://discuss.ocaml.org/t/juxtaposition-in-menhir/9782 "2025-03-27T17:44:41Z")

</div>

I would like to use “simple” precedence rules to write a parser in Menhir for a grammar where juxtaposition is right-associative function application (like OCaml syntax, so e.g. f g x should be parsed Apply (Apply (Var "…

---

## [Menhir's solution for handling double angle brackets differently in type and term contexts?](https://discuss.ocaml.org/t/menhirs-solution-for-handling-double-angle-brackets-differently-in-type-and-term-contexts/15998)

<div class="topic-metadata">

**Author:** [@osa1](https://discuss.ocaml.org/u/osa1)\
**Replies:** 13\
**Last updated:** [January 24, 2025, 11:02am UTC](https://discuss.ocaml.org/t/menhirs-solution-for-handling-double-angle-brackets-differently-in-type-and-term-contexts/15998 "2025-01-24T11:02:49Z")

</div>

A common parsing problem in languages that use angle brackets for generics is that you can’t tokenize “\>\>” as the right shift operator as in type context it would need to be parsed as two closing angle brackets. However…

---

## [Solving shift/reduce conflicts for optional trailing comma in menhir](https://discuss.ocaml.org/t/solving-shift-reduce-conflicts-for-optional-trailing-comma-in-menhir/15042)

<div class="topic-metadata">

**Author:** [@ttzytt](https://discuss.ocaml.org/u/ttzytt)\
**Replies:** 4\
**Last updated:** [July 30, 2024, 7:34am UTC](https://discuss.ocaml.org/t/solving-shift-reduce-conflicts-for-optional-trailing-comma-in-menhir/15042 "2024-07-30T07:34:18Z")

</div>

Optional trailing commas (or other symbols) are quite a common feature in various programming languages. For example, Rust allows you to add a trailing comma at the end of an array like this ( Array and index expression…

---

## [Menhir generating empty conflicts file?](https://discuss.ocaml.org/t/menhir-generating-empty-conflicts-file/14882)

<div class="topic-metadata">

**Author:** [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Replies:** 0\
**Last updated:** [June 29, 2024, 7:00pm UTC](https://discuss.ocaml.org/t/menhir-generating-empty-conflicts-file/14882 "2024-06-29T19:00:17Z")

</div>

in the past, I’ve used menhir’s .conflicts file to debug my grammars with excellent effect. Yesterday I was working with a grammar, and have 8 “productions are never reduced” conflicts, and the .conflicts file is empty.…

---

## [Include\_subdirs qualified + menhir produces unbound module](https://discuss.ocaml.org/t/include-subdirs-qualified-menhir-produces-unbound-module/14514)

<div class="topic-metadata">

**Author:** [@Vanille-N](https://discuss.ocaml.org/u/Vanille-N)\
**Replies:** 0\
**Last updated:** [April 18, 2024, 11:49am UTC](https://discuss.ocaml.org/t/include-subdirs-qualified-menhir-produces-unbound-module/14514 "2024-04-18T11:49:08Z")

</div>

TL;DR I am working with dune and have the option (include\_subdirs qualified). I’m trying to move the files related to parsing (Syntax.mly, Ast.ml, Tokens.mll) to a subdirectory Parsing. Unfortunately Ast.ml specifically…

---

## [Using Menhir to parse into idiomatic JS (TypeScript) structures](https://discuss.ocaml.org/t/using-menhir-to-parse-into-idiomatic-js-typescript-structures/13809)

<div class="topic-metadata">

**Author:** [@shonfeder](https://discuss.ocaml.org/u/shonfeder)\
**Replies:** 0\
**Last updated:** [January 7, 2024, 4:16pm UTC](https://discuss.ocaml.org/t/using-menhir-to-parse-into-idiomatic-js-typescript-structures/13809 "2024-01-07T16:16:56Z")

</div>

Hello and Happy New Year! As we all know, despite being named an Objective Categorical Abstract Machine Language, OCaml is Obviously a Completely Awesome Meta Language. The awesomeness is founded on the wonderful langua…

---

## [How to use \`menhir --explain\` with dune?](https://discuss.ocaml.org/t/how-to-use-menhir-explain-with-dune/11132)

<div class="topic-metadata">

**Author:** [@thierry-martinez](https://discuss.ocaml.org/u/thierry-martinez)\
**Replies:** 9\
**Last updated:** [January 2, 2024, 11:39am UTC](https://discuss.ocaml.org/t/how-to-use-menhir-explain-with-dune/11132 "2024-01-02T11:39:48Z")

</div>

I use the (menhir) stanza in dune to compile grammars, but I don’t know how to conveniently use the menhir --explain feature. The naïve approach of using (flags --explain) used to work before the level of sandboxing int…

---

## [Sanity check on grammar for tree language](https://discuss.ocaml.org/t/sanity-check-on-grammar-for-tree-language/13711)

<div class="topic-metadata">

**Author:** [@CharlesAverill](https://discuss.ocaml.org/u/CharlesAverill)\
**Replies:** 1\
**Last updated:** [December 25, 2023, 12:51pm UTC](https://discuss.ocaml.org/t/sanity-check-on-grammar-for-tree-language/13711 "2023-12-25T12:51:42Z")

</div>

Writing a parser for Pascal parse tree dump files, which can contain tree structures with multiple children like: (node A (node B) (node C) (node D (node F) ) ) (where B, C, and D are children of A, …

---

## [How does Menhir's option() work?](https://discuss.ocaml.org/t/how-does-menhirs-option-work/13491)

<div class="topic-metadata">

**Author:** [@vdolgov](https://discuss.ocaml.org/u/vdolgov)\
**Replies:** 5\
**Last updated:** [November 24, 2023, 4:18pm UTC](https://discuss.ocaml.org/t/how-does-menhirs-option-work/13491 "2023-11-24T16:18:35Z")

</div>

I’m writing an Objective-C parser with Menhir and cannot figure out why the following rule | CARET; t = option(LPAREN s=IDENT ASTERISK? RPAREN { s }) LPAREN l = separated\_list(COMMA, t=IDENT ASTERISK\* s=IDENT { (t, s) }…

---

## [Menhir as a parser within editors (or tree-sitter?)](https://discuss.ocaml.org/t/menhir-as-a-parser-within-editors-or-tree-sitter/12765)

<div class="topic-metadata">

**Author:** [@meitros](https://discuss.ocaml.org/u/meitros)\
**Replies:** 3\
**Last updated:** [August 24, 2023, 12:03pm UTC](https://discuss.ocaml.org/t/menhir-as-a-parser-within-editors-or-tree-sitter/12765 "2023-08-24T12:03:57Z")

</div>

I have a custom language with a parser written in menhir, and I’m now developing a codemirror editor for it. I’ve read that tree-sitter (and Lezer, the codemirror specific version of it) are highly optimized for being go…

---

## [Gynormous memory consumption to compile output of Menhir](https://discuss.ocaml.org/t/gynormous-memory-consumption-to-compile-output-of-menhir/12011)

<div class="topic-metadata">

**Author:** [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Replies:** 6\
**Last updated:** [April 25, 2023, 6:39pm UTC](https://discuss.ocaml.org/t/gynormous-memory-consumption-to-compile-output-of-menhir/12011 "2023-04-25T18:39:38Z")

</div>

I’m hacking on the official OCaml grammar, in a manner that increases the size of the grammar significantly: from 3MB of generated code to 10MB, and I’m seeing the memory footprint of the “ocamlc” bytecode compiler proce…

---

## [Divergence on loading OCaml grammar into toplevel?](https://discuss.ocaml.org/t/divergence-on-loading-ocaml-grammar-into-toplevel/11619)

<div class="topic-metadata">

**Author:** [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Replies:** 2\
**Last updated:** [March 8, 2023, 9:29pm UTC](https://discuss.ocaml.org/t/divergence-on-loading-ocaml-grammar-into-toplevel/11619 "2023-03-08T21:29:47Z")

</div>

I’m trying to hack on the OCaml grammar, and finding that I can’t load it into the toplevel. I looked at the HACKING.adoc file, and found nothing there that addressed what I’m seeing. I wondered if I’m doing something …

---

## [Parsing negative integers in a calculator](https://discuss.ocaml.org/t/parsing-negative-integers-in-a-calculator/11588)

<div class="topic-metadata">

**Author:** [@gaganchandan](https://discuss.ocaml.org/u/gaganchandan)\
**Replies:** 2\
**Last updated:** [March 5, 2023, 8:21pm UTC](https://discuss.ocaml.org/t/parsing-negative-integers-in-a-calculator/11588 "2023-03-05T20:21:03Z")

</div>

I’m new to Menhir and I’m trying to implement a calculator using it. I’m aiming to include negative integers in my calculator as well. But I’m having trouble with one specific kind of expression. My parser fails when it …

---

## [Lexer rule to create multiple tokens from a match](https://discuss.ocaml.org/t/lexer-rule-to-create-multiple-tokens-from-a-match/11521)

<div class="topic-metadata">

**Author:** [@intermet](https://discuss.ocaml.org/u/intermet)\
**Replies:** 5\
**Last updated:** [February 27, 2023, 1:15pm UTC](https://discuss.ocaml.org/t/lexer-rule-to-create-multiple-tokens-from-a-match/11521 "2023-02-27T13:15:39Z")

</div>

Hi! I am writing a lexer. Typical strings to tokenize are "Push 1" "Push 1 2" I am parsing a programming language and push means pushing to the stack. "Push 1" push '1' to the stack and "Push 1 2" pushes '1' and then '…

---

## [Menhir:How to use inline to add locations?](https://discuss.ocaml.org/t/menhir-how-to-use-inline-to-add-locations/11025)

<div class="topic-metadata">

**Author:** [@liweijian](https://discuss.ocaml.org/u/liweijian)\
**Replies:** 2\
**Last updated:** [December 22, 2022, 10:50am UTC](https://discuss.ocaml.org/t/menhir-how-to-use-inline-to-add-locations/11025 "2022-12-22T10:50:36Z")

</div>

I saw this trick from Your favorite Menhir tricks and fanciness , which is very impressive (cc @EmileTrotignon ): %public %inline located(X): x=X { Position.with\_poss $startpos $endpos x } I tried to make a demo to tes…

---

## [How do I get better error messages from Menhir?](https://discuss.ocaml.org/t/how-do-i-get-better-error-messages-from-menhir/10764)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 0\
**Last updated:** [November 5, 2022, 7:16pm UTC](https://discuss.ocaml.org/t/how-do-i-get-better-error-messages-from-menhir/10764 "2022-11-05T19:16:40Z")

</div>

Right now, my Menhir parser will show this error message for any parse error: Fatal error: exception Dune\_\_exe\_\_Main.Parser\_error("tok = {, Could not parse … And then the entire source file is included in the message…

---

## [Is there a tool to format ocamllex and menhir files?](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789)

<div class="topic-metadata">

**Author:** [@ale](https://discuss.ocaml.org/u/ale)\
**Replies:** 5\
**Last updated:** [October 21, 2022, 9:21pm UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789 "2022-10-21T21:21:46Z")

</div>

I use ocamlformat extensively and it would be awesome to have a similar tool to format lexer and parser files as well. Is there any such tool?

---

## [Debugging Menhir - how?](https://discuss.ocaml.org/t/debugging-menhir-how/10646)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 3\
**Last updated:** [October 15, 2022, 1:14pm UTC](https://discuss.ocaml.org/t/debugging-menhir-how/10646 "2022-10-15T13:14:57Z")

</div>

method call threw Pholyglot\_\_Parser.MenhirBasics.Error. This is slightly annoying. I have an error in my grammar and need to trace through what’s happening. Any tips…? I can look at the generated parser.ml file for cl…

---

## [Recursion in Menhir lexer for small DSL](https://discuss.ocaml.org/t/recursion-in-menhir-lexer-for-small-dsl/10566)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 31\
**Last updated:** [October 5, 2022, 4:08pm UTC](https://discuss.ocaml.org/t/recursion-in-menhir-lexer-for-small-dsl/10566 "2022-10-05T16:08:03Z")

</div>

I need to lex and parse a small DSL inside my language, related to the docblock: /\*\* \* @param array\<int\> $ints \*/ function foo(array &$ints): void { } The DSL is the @param part, and the main lang…

---

## [Dune error when adding a second parser to a Menhir project](https://discuss.ocaml.org/t/dune-error-when-adding-a-second-parser-to-a-menhir-project/10569)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 1\
**Last updated:** [October 3, 2022, 9:55am UTC](https://discuss.ocaml.org/t/dune-error-when-adding-a-second-parser-to-a-menhir-project/10569 "2022-10-03T09:55:07Z")

</div>

Edit: Sorry, I think was actually a simple file naming error… Imagine if the error said “no such file” instead. :joy: Sorry for spamming the forum. Not much beginner info available online, I’m afraid. So, I’m testing t…

---

## [Call Menhir-generated parser without a lexbuf](https://discuss.ocaml.org/t/call-menhir-generated-parser-without-a-lexbuf/10570)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 8\
**Last updated:** [October 2, 2022, 8:16pm UTC](https://discuss.ocaml.org/t/call-menhir-generated-parser-without-a-lexbuf/10570 "2022-10-02T20:16:15Z")

</div>

OK, so I’ve setup two parsers, and one lexer. I’m getting a token list from the lexer, then call the second parser from the first parser. BUT, now the second parser expects a lexbuf, when I already have a token list (and…

---

## [How to parse a token with a list argument in Menhir?](https://discuss.ocaml.org/t/how-to-parse-a-token-with-a-list-argument-in-menhir/10567)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 7\
**Last updated:** [October 2, 2022, 10:56am UTC](https://discuss.ocaml.org/t/how-to-parse-a-token-with-a-list-argument-in-menhir/10567 "2022-10-02T10:56:34Z")

</div>

So I just added %token \<token list\> DOCBLOCK to my parser, and now I have no idea how to actually write a grammar for it. Would appreciate any link to example or relevant parts of documentation. Especially confused by…

---

## [\[Discussion\] Writing a transpiler from PHP to polyglot PHP+C code](https://discuss.ocaml.org/t/discussion-writing-a-transpiler-from-php-to-polyglot-php-c-code/10301)

<div class="topic-metadata">

**Author:** [@olleharstedt](https://discuss.ocaml.org/u/olleharstedt)\
**Replies:** 3\
**Last updated:** [August 18, 2022, 8:39pm UTC](https://discuss.ocaml.org/t/discussion-writing-a-transpiler-from-php-to-polyglot-php-c-code/10301 "2022-08-18T20:39:27Z")

</div>

So it’s possible to write polyglot code that both compiles in C and runs in PHP, with a couple of tricks and helper functions. Example code here: pholyglot/polyglot.c at main · olleharstedt/pholyglot · GitHub Now I’m th…

---

## [Assertion Failure with Menhir 20220210 and --interpret-show-cst](https://discuss.ocaml.org/t/assertion-failure-with-menhir-20220210-and-interpret-show-cst/9486)

<div class="topic-metadata">

**Author:** [@totbwf](https://discuss.ocaml.org/u/totbwf)\
**Replies:** 3\
**Last updated:** [March 11, 2022, 6:13am UTC](https://discuss.ocaml.org/t/assertion-failure-with-menhir-20220210-and-interpret-show-cst/9486 "2022-03-11T06:13:06Z")

</div>

The Menhir Gitlab instance seems to require an invite before raising an issue, so I figured this would be a good a place as any: When using Menhir 20220210, if you pass the --interpret-show-cst flag, it will crash with …

---

## [Implementing an include statement in menhir \> 20211123](https://discuss.ocaml.org/t/implementing-an-include-statement-in-menhir-20211123/9271)

<div class="topic-metadata">

**Author:** [@rwmjones](https://discuss.ocaml.org/u/rwmjones)\
**Replies:** 6\
**Last updated:** [March 10, 2022, 3:12pm UTC](https://discuss.ocaml.org/t/implementing-an-include-statement-in-menhir-20211123/9271 "2022-03-10T15:12:22Z")

</div>

Back in the day I was helped with implementing an include statement in my custom menhir-based language, and this worked fine: http://git.annexia.org/?p=goals.git;a=blob;f=src/parser.mly;h=9b1a91247767be286ec48f691b1c54b…

[Next page](https://discuss.ocaml.org/tag/menhir/155.md?match_all_tags=true&page=1&tags%5B%5D=menhir)
