For reference, I also had the same problem (e.g. using menhir’s messages feature, and making sure the messages file stays up to date), and I managed to write some rules that give me a reasonable solution, that you can find here.
Basically the trick is to:
- have a messages file containing your error messages (
syntax.messages
in the dune file linked) - have some rules to generate an updated version of your messages files. To do that, the dune file:
- generates a new messages files from the
.mly
file (this isnew.messages
), this contains empty/dummy error messages for all the states from your parser - create an updated version of the current messages file (mainly to update state number and if I recall correctly, remove messages for now non-existing states)
- merge these two files using the dedicated menhir feature. This results in a messages file that contains all of the original messages, plus empty/dummy error messages for new states, and minus the now non-existing states
- generates a new messages files from the
- lastly, have a dune test that diffs the current messages files (the one commited in the repo), with the one generated by the step above. That way, when running tests, you’ll get an error if some states are missing from your message file, and you can easily use the promote feature to update you message file, and then update the message for the new states by hand (following the diff that was printed by the test).