Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menhir: a new rule for the --compile-errors support #121

Open
gasche opened this issue Nov 15, 2016 · 5 comments
Open

Menhir: a new rule for the --compile-errors support #121

gasche opened this issue Nov 15, 2016 · 5 comments

Comments

@gasche
Copy link
Member

gasche commented Nov 15, 2016

See this Stackoverflow question: the last version of Menhir has an error-message-generation interface that can be used as follows:

src/ParsingErrors.ml: src/Handcrafted.messages src/Parser.mly
    menhir --compile-errors src/Handcrafted.messages src/Parser.mly > src/ParsingErrors.ml

it would be nice to have a generic ocamlbuild rule for that.

@gasche
Copy link
Member Author

gasche commented Nov 15, 2016

A first question is what the general naming convention should be. The parser Foo.mly may expect a message file with the name Foo.messages, but what then is the expected name of the resulting .ml file?

Given that menhir generates the code to the standard output by default, it may not be intended as a self-contained complete OCaml source file -- I suppose that the workflow that @fpottier had in mind is that users would manually insert the function in their codebase? In that case, a name such as Foo.errrors.ml may be appropriate. But the Makefile rule shown in the StackOverflow question suggests that users do use it directly as an OCaml module, in that case we need a valid OCaml module name, for example Foo_errors.ml -- but I dislike the idea of modifying the basename.

@fpottier
Copy link
Contributor

I have posted an answer on StackOverflow. In short, there are generic rules in Menhir's own myocamlbuild.ml, which could possibly move into ocamlbuild's standard set of rules. My naming convention is to store the code produced by the command menhir Foo.mly --compile-errors Foo.messages in the file FooMessages.ml.

@gasche
Copy link
Member Author

gasche commented Nov 16, 2016

I'm a bit frustrated by the current situation where I run after new Menhir features (I'm really glad Menhir is actively evolving) to encode them in upstream ocamlbuild in a worse way than what you are already doing yourself. (On the other hand there is an impedance mismatch in the sense that the code your write is less generic, it is partly only in the context of Menhir's own build system.)

It would be nice to evolve in a situation where Menhir would provide an ocamlbuild plugin library, to be use by users of ocamlbuild+Menhir. But I don't see a way to make that translation smooth, except maybe by making ocamlbuild depend on it or include it (so it would need to be distributed separately from Menhir itself?).

On the other hand, you ( @fpottier ) have been forthcoming in the past in contributing flags for new Menhir options. Maybe the current arrangement can keep working: I'm of course happy to upstream any contributions on the Menhir support in ocamlbuild, but right now I don't have the time to do the work to digest your rules, generalize them, and push them in ocamlbuild myself, so a PR from you -- if you think this is a legitimate request for Menhir users would be warmly appreciated.

I looked a bit more at your myocamlbuild.ml code. It looks like there are several more rules that could be profitable (typically the generation of an initial .messages file from the grammar). The handling of .witness and diffing etc. also looks a bit complex, but I guess it's fine as long as this complexity is mostly hidden from users or well-documented in Menhir.

@fpottier
Copy link
Contributor

Hi Gabriel,

Le 16/11/2016 23:12, Gabriel Scherer a écrit :

a PR from you -- if you think this is a legitimate request for Menhir users
would be warmly appreciated.

Sure, I could do that, if time permits. I am adding it to my todo list.

If we copy some rules from Menhir's build system into ocamlbuild's
distribution, will I run into difficulties when building Menhir?
Two copies of the rules will exist, one in ocamlbuild's default rule
set, one in Menhir's myocamlbuild.ml. What happens then?

(I could try to avoid the problem by removing the rules from Menhir's
myocamlbuild.ml and requiring a recent version of ocamlbuild, but this
does not eliminate the problem entirely; some people might still try to
build an old Menhir using a new ocamlbuild.)

François Pottier
francois.pottier@inria.fr
http://gallium.inria.fr/~fpottier/

@gasche
Copy link
Member Author

gasche commented Nov 17, 2016

ocamlbuild has some notion of rule priorities (you can actually specify stuff using the ?insert parameter, see the manual), but in any case if the two rules are identical it doesn't really matter which one is selected, it should just work.

P.S.: Sorry for the somewhat grumpy tone of my previous message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants