From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Helmut Brandl <helmut.brandl@gmx.net>
Cc: caml users <caml-list@inria.fr>,
Francois Pottier <francois.pottier@inria.fr>
Subject: Re: [Caml-list] Menhir incremental api with ocamlbuild
Date: Tue, 28 Feb 2017 22:57:17 -0500 [thread overview]
Message-ID: <CAPFanBF75utqyxjUCgJEEkuZV89cNXtBc6jSSo-0=G26dp=xEQ@mail.gmail.com> (raw)
In-Reply-To: <7C984183-3E3A-4698-8597-342888F7E53B@gmx.net>
[-- 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 --]
next prev parent reply other threads:[~2017-03-01 3:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-01 3:30 Helmut Brandl
2017-03-01 3:57 ` Gabriel Scherer [this message]
2017-03-01 6:55 ` François Pottier
2017-03-01 13:49 ` Helmut Brandl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPFanBF75utqyxjUCgJEEkuZV89cNXtBc6jSSo-0=G26dp=xEQ@mail.gmail.com' \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=francois.pottier@inria.fr \
--cc=helmut.brandl@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).