# Is there a tool to format ocamllex and menhir files?

**URL:** <https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789>\
**Category:** Ecosystem\
**Tags:** ocamlformat, menhir, format\
**Created:** [May 12, 2019, 12:03am UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789 "2019-05-12T00:03:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ale](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ale/32/1540_2.png) [@ale](https://discuss.ocaml.org/u/ale)\
**Post date:** [May 12, 2019, 12:03am UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789/1 "2019-05-12T00:03:44Z")

</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?

---

<div class="post-metadata">

**Author:** ![avsm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/avsm/32/6_2.png) [@avsm](https://discuss.ocaml.org/u/avsm)\
**Post date:** [May 12, 2019, 1:18pm UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789/2 "2019-05-12T13:18:19Z")

</div>

Glad to hear ocamlformat is working out for you! Formatting other related formats such as lex, yacc (and toplevel) scripts has come up before, and should be in scope for the core tool (since these formats spring from the core OCaml distribution). A [feature request](https://github.com/ocaml-ppx/ocamlformat/issues) on the issue tracker would be most welcome.

---

<div class="post-metadata">

**Author:** ![let-def](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/let-def/32/2948_2.png) [@let-def](https://discuss.ocaml.org/u/let-def)\
**Post date:** [May 12, 2019, 2:45pm UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789/3 "2019-05-12T14:45:35Z")

</div>

Once we have a fairly self contained grammar for lex & yacc, it will be fairly easy to add support to Merlin too.

---

<div class="post-metadata">

**Author:** ![spop](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/spop/32/797_2.png) [@spop](https://discuss.ocaml.org/u/spop)\
**Post date:** [May 12, 2019, 6:16pm UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789/4 "2019-05-12T18:16:09Z")

</div>

. **ocp-indent** gives a very basic support for .mll files

by adding the line:  
_syntax=mll_  
in the .ocp-indent file.

. No support for .mly files.

Issue open (long time ago…)

> <https://github.com/OCamlPro/ocp-indent/issues/218>

---

<div class="post-metadata">

**Author:** ![ale](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ale/32/1540_2.png) [@ale](https://discuss.ocaml.org/u/ale)\
**Post date:** [May 14, 2019, 12:25am UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789/5 "2019-05-14T00:25:47Z")

</div>

Thanks. Done: [https://github.com/ocaml-ppx/ocamlformat/issues/830](https://github.com/ocaml-ppx/ocamlformat/issues/830)

---

<div class="post-metadata">

**Author:** ![Butanium](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/butanium/32/2930_2.png) [@Butanium](https://discuss.ocaml.org/u/Butanium)\
**Post date:** [October 21, 2022, 9:21pm UTC](https://discuss.ocaml.org/t/is-there-a-tool-to-format-ocamllex-and-menhir-files/3789/6 "2022-10-21T21:21:46Z")

</div>

Any news about this ?
