Simplify ocamllex/ocamlyacc rules
They are tricky and don't work properly
This commit is contained in:
parent
ac372ce63a
commit
19dae96f1a
|
@ -1398,48 +1398,19 @@ module Gen(P : Params) = struct
|
|||
let ocamllex_rules (conf : Ocamllex.t) ~dir =
|
||||
List.iter conf.names ~f:(fun name ->
|
||||
let src = Path.relative dir (name ^ ".mll" ) in
|
||||
let tmp = Path.relative dir (name ^ ".tmp.ml") in
|
||||
let dst = Path.relative dir (name ^ ".ml" ) in
|
||||
add_rule
|
||||
(Build.run (Dep ctx.ocamllex) [A "-q"; A "-o"; Path tmp; Dep src]
|
||||
>>>
|
||||
Build.create_file ~target:dst (fun () ->
|
||||
let repl = Path.to_string (Path.append ctx.build_dir dst) in
|
||||
let tmp = Path.to_string tmp in
|
||||
let dst = Path.to_string dst in
|
||||
Rewrite_generated_file.rewrite ~src:tmp ~dst ~repl;
|
||||
Sys.remove tmp)))
|
||||
(Build.run (Dep ctx.ocamllex) [A "-q"; A "-o"; Target dst; Dep src]))
|
||||
|
||||
let ocamlyacc_rules (conf : Ocamlyacc.t) ~dir =
|
||||
List.iter conf.names ~f:(fun name ->
|
||||
let src = Path.relative dir (name ^ ".mly" ) in
|
||||
let tmp = Path.relative dir (name ^ ".tmp.ml" ) in
|
||||
let tmpi = Path.relative dir (name ^ ".tmp.mli") in
|
||||
let dst = Path.relative dir (name ^ ".ml" ) in
|
||||
let dsti = Path.relative dir (name ^ ".mli" ) in
|
||||
add_rule
|
||||
(Build.run
|
||||
(Build.run ~extra_targets:[dst; dsti]
|
||||
(Dep ctx.ocamlyacc)
|
||||
[ A "-b"
|
||||
; Path (Path.relative dir (name ^ ".tmp"))
|
||||
; Dep src
|
||||
]
|
||||
>>>
|
||||
Build.create_files ~targets:[dst; dsti] (fun () ->
|
||||
let repl = Path.to_string (Path.append ctx.build_dir dst) in
|
||||
let tmp = Path.to_string tmp in
|
||||
let dst = Path.to_string dst in
|
||||
Rewrite_generated_file.rewrite ~src:tmp ~dst ~repl;
|
||||
Sys.remove tmp;
|
||||
|
||||
let repli = Path.to_string (Path.append ctx.build_dir dsti) in
|
||||
let tmpi = Path.to_string tmpi in
|
||||
let dsti = Path.to_string dsti in
|
||||
with_file_in tmpi ~f:(fun ic ->
|
||||
with_file_out dsti ~f:(fun oc ->
|
||||
Printf.fprintf oc "# 1 \"%s\"\n" repli;
|
||||
copy_channels ic oc));
|
||||
Sys.remove tmpi)))
|
||||
[ Dep src ]))
|
||||
|
||||
(* +-----------------------------------------------------------------+
|
||||
| Modules listing |
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
(public_name jbuilder)
|
||||
(libraries (unix jbuilder_re))))
|
||||
|
||||
(ocamllex (sexp_lexer meta_lexer rewrite_generated_file glob_lexer))
|
||||
(ocamllex (sexp_lexer meta_lexer glob_lexer))
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
val rewrite : src:string -> dst:string -> repl:string -> unit
|
|
@ -1,20 +0,0 @@
|
|||
{ open Import }
|
||||
|
||||
rule iter src repl oc = parse
|
||||
| ("# " ['0'-'9']+ " \"" as before) ([^'"' '\n']* as name) ('"' '\r'? '\n' as after)
|
||||
{ output_string oc before;
|
||||
output_string oc (if name = src then repl else name);
|
||||
output_string oc after;
|
||||
iter src repl oc lexbuf }
|
||||
| [^'\n']* '\n' as s
|
||||
{ output_string oc s;
|
||||
iter src repl oc lexbuf }
|
||||
| [^'\n']* eof as s
|
||||
{ output_string oc s }
|
||||
|
||||
{
|
||||
let rewrite ~src ~dst ~repl =
|
||||
with_file_in src ~f:(fun ic ->
|
||||
with_file_out dst ~f:(fun oc ->
|
||||
iter src repl oc (Lexing.from_channel ic)))
|
||||
}
|
Loading…
Reference in New Issue