Dependency cycle problem

Hey :slight_smile:

I am currently working on a prototype for a parser generator in OCaml. If I have a grammar description in a file parser.abc I can generate an .ml file with the actual parser code like so:

abc parser.abc -o parser

This will generate the file parser.ml. All of this works fine as long as I do it manually on the command line. Now I want to integrate it with dune to automate the generation of the .ml file. In my current setup, I have a lexer in lexer.mll and the grammar in parser.abc. I have tried the following:

(rule
(target parser)
(deps parser.abc)
(action (run abc %{deps} -o %{target}))))

(ocamllex
(modules lexer)
(enabled_if %{read:parser.ml}))

However, this results in:

Error: Dependency cycle between:
Computing directory contents of _build/default/examples/arith
→ %{read:parser} at examples/arith/dune:12
→ Computing directory contents of _build/default/examples/arith

Now I have also tried to put the grammar into a different directory and use a subdir stanza, however, that still did not work. Is there a way of specifying the order in which the different stanzas shall be invoked?

Thanks for any input!

You don’t need the enabled_if: the ocamllex stanza only generates the lexer code and does not compile it, so it does not need to have access to parser.ml. parser.ml will only be necessary in order to compile the generated code in lexer.ml, and then the dependencies will be found automatically by Dune so you won’t have to write anything special for it.

Cheers,
Nicolas

That worked like a charm! Thank you :slight_smile: