* [Caml-list] Menhir incremental api with ocamlbuild
@ 2017-03-01 3:30 Helmut Brandl
2017-03-01 3:57 ` Gabriel Scherer
0 siblings, 1 reply; 4+ messages in thread
From: Helmut Brandl @ 2017-03-01 3:30 UTC (permalink / raw)
To: caml-list
Hello list,
does anybody know how to build a project with ocamlbuild and use the incremental api of menhir. By using menhir directly I would use the ‘-table’ flag. But I don’t know how to transfer this flag to menhir by using ocamlbuild.
Kind regards
Helmut
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Menhir incremental api with ocamlbuild
2017-03-01 3:30 [Caml-list] Menhir incremental api with ocamlbuild Helmut Brandl
@ 2017-03-01 3:57 ` Gabriel Scherer
2017-03-01 6:55 ` François Pottier
0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Scherer @ 2017-03-01 3:57 UTC (permalink / raw)
To: Helmut Brandl; +Cc: caml users, Francois Pottier
[-- Attachment #1: Type: text/plain, Size: 3455 bytes --]
Indeed, ocamlbuild misses some built-in flag for menhir features. That
said, it is easy to add these flags through your myocamlbuild.ml. Here is
what I have in an incremental-menhir-using project (inside a dispatch call):
flag ["menhir"; "parser"; "trace"] (A"--trace");
flag ["menhir"; "parser"; "table"] (A "--table");
flag ["menhir"; "parser"; "canonical"] (A"--canonical");
but it would be easy to add those to the built-in -use-menhir mode.
(If you are not comfortable with using myocamlbuild.ml, see the ocamlbuild
manual:
https://github.com/ocaml/ocamlbuild/blob/master/manual/manual.adoc#Sec_Plugins
)
In this project I also have rules for handling of .messages files
corresponding Menhir's new error message support. I include the complete
code at the end of my email. I would like to get a bit more experience
using those, before considering including them in ocamlbuild proper.
----
module Menhir = struct
let menhir () =
if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc
let menhir_tags mly =
tags_of_pathname mly ++"ocaml"++"parser"++"menhir"
let menhir_produce_messages env build =
let messages, mly = env "%.messages", env "%.mly" in
let open Ocamlbuild_pack in
Ocaml_compiler.prepare_compile build mly;
Cmd(S[menhir (); T (menhir_tags mly);
A "--list-errors"; P mly; Sh ">"; Px messages])
let menhir_compile_messages env build =
let mly = env "%.mly" in
let messages = env "%.messages" in
let target = env "%_messages.ml" in
Cmd(S[menhir (); T (menhir_tags mly); P mly;
A "--compile-errors"; P messages;
Sh ">"; Px target])
let menhir_update_messages env build =
let mly = env "%.mly" in
let messages = env "%.messages" in
let tmp = Filename.temp_file "menhir" ".messages" in
Seq [
Cmd(S[menhir (); T (menhir_tags mly); P mly;
A "--update-errors"; P messages;
Sh ">"; P tmp]);
Cmd(S[A "mv"; P tmp; P messages]);
]
let dispatcher = function
| After_rules ->
flag ["menhir"; "parser"; "menhir_trace"] (A"--trace");
flag ["menhir"; "parser"; "menhir_table"] (A "--table");
flag ["menhir"; "parser"; "menhir_canonical"] (A"--canonical");
rule "menhir: .mly -> .messages"
~prod:"%.messages"
~deps:["%.mly"]
menhir_produce_messages;
rule "menhir: .mly & .messages -> _messages.ml"
~prod:"%_messages.ml"
~deps:["%.mly"; "%.messages"]
menhir_compile_messages;
rule "menhir: .mly & .messages -> .messages & .messages.update"
~stamp:"%.messages.update"
~deps:["%.mly"; "%.messages"]
menhir_update_messages;
| _ -> ()
end
On Tue, Feb 28, 2017 at 10:30 PM, Helmut Brandl <helmut.brandl@gmx.net>
wrote:
> Hello list,
>
> does anybody know how to build a project with ocamlbuild and use the
> incremental api of menhir. By using menhir directly I would use the
> ‘-table’ flag. But I don’t know how to transfer this flag to menhir by
> using ocamlbuild.
>
> Kind regards
> Helmut
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
[-- Attachment #2: Type: text/html, Size: 5386 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Menhir incremental api with ocamlbuild
2017-03-01 3:57 ` Gabriel Scherer
@ 2017-03-01 6:55 ` François Pottier
2017-03-01 13:49 ` Helmut Brandl
0 siblings, 1 reply; 4+ messages in thread
From: François Pottier @ 2017-03-01 6:55 UTC (permalink / raw)
To: Gabriel Scherer, Helmut Brandl; +Cc: caml users
Thanks Gabriel.
Another quick-and-dirty approach is to just use
ocamlbuild -use-menhir -menhir "menhir --table".
--
François Pottier
francois.pottier@inria.fr
http://gallium.inria.fr/~fpottier/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Menhir incremental api with ocamlbuild
2017-03-01 6:55 ` François Pottier
@ 2017-03-01 13:49 ` Helmut Brandl
0 siblings, 0 replies; 4+ messages in thread
From: Helmut Brandl @ 2017-03-01 13:49 UTC (permalink / raw)
To: François Pottier; +Cc: caml users
I have found another solution. The command
ocamlbuild -yaccflag —table ...
does the job. Thanks for the hints.
> On Mar 1, 2017, at 00:55, François Pottier <francois.pottier@inria.fr> wrote:
>
>
> Thanks Gabriel.
>
> Another quick-and-dirty approach is to just use
> ocamlbuild -use-menhir -menhir "menhir --table".
>
> --
> François Pottier
> francois.pottier@inria.fr
> http://gallium.inria.fr/~fpottier/
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-01 13:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-01 3:30 [Caml-list] Menhir incremental api with ocamlbuild Helmut Brandl
2017-03-01 3:57 ` Gabriel Scherer
2017-03-01 6:55 ` François Pottier
2017-03-01 13:49 ` Helmut Brandl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox