-
Notifications
You must be signed in to change notification settings - Fork 5
/
myocamlbuild.ml
57 lines (51 loc) · 1.76 KB
/
myocamlbuild.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
open Ocamlbuild_plugin
module Pack = Ocamlbuild_pack
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 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 _ = dispatch begin fun hook ->
Bisect_ppx_plugin.dispatch hook;
match hook with
| Before_options ->
Options.use_ocamlfind := true;
Options.use_menhir := true;
| After_rules ->
flag ["menhir"; "parser"; "menhir_table"] (A "--table");
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