Skip to content

Commit 3bafa21

Browse files
authored
Track differences between the various ocaml parsers (ocaml-ppx#1783)
1 parent 4c1ac5f commit 3bafa21

25 files changed

+12583
-1
lines changed

tools/diff-parsers/diff_parsers.ml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
let diff d1 d2 f =
2+
let f1 = Filename.concat d1 f in
3+
let f2 = Filename.concat d2 f in
4+
if Sys.file_exists f2 then
5+
Sys.command
6+
(Printf.sprintf
7+
{|diff -U 5 -L %s %s -L %s %s | sed 's/^@@ .* @@$/@@@@/g'|} f1 f1 f2
8+
f2 )
9+
else 0
10+
11+
let import version dir f =
12+
Sys.command
13+
(Printf.sprintf
14+
"curl -s -o %s \
15+
https://raw.githubusercontent.com/ocaml/ocaml/%s/parsing/%s"
16+
(Filename.concat dir f) version f )
17+
18+
let files =
19+
[ "ast_helper.ml"
20+
; "ast_helper.mli"
21+
; "ast_mapper.ml"
22+
; "ast_mapper.mli"
23+
; "asttypes.mli"
24+
; "docstrings.ml"
25+
; "docstrings.mli"
26+
; "lexer.mll"
27+
; "parse.ml"
28+
; "parse.mli"
29+
; "parser.mly"
30+
; "parsetree.mli"
31+
; "pprintast.ml"
32+
; "pprintast.mli" ]
33+
34+
let usage () =
35+
let exe = Filename.basename Sys.executable_name in
36+
Printf.printf "usage:\n\n%s diff DIR1 DIR2\n\n%s import VERSION DIR" exe
37+
exe ;
38+
exit 1
39+
40+
let () =
41+
let l = List.tl (Array.to_list Sys.argv) in
42+
match l with
43+
| "diff" :: args -> (
44+
match args with
45+
| [d1; d2] -> (
46+
let codes = List.map (diff d1 d2) files in
47+
let non_zero =
48+
List.filter (function 0 | 1 -> false | _ -> true) codes
49+
in
50+
match non_zero with [] -> () | first :: _ -> exit first )
51+
| _ -> usage () )
52+
| "import" :: args -> (
53+
match args with
54+
| [version; dir] -> (
55+
let codes = List.map (import version dir) files in
56+
let non_zero =
57+
List.filter (function 0 -> false | _ -> true) codes
58+
in
59+
match non_zero with [] -> () | first :: _ -> exit first )
60+
| _ -> usage () )
61+
| _ -> usage ()

tools/diff-parsers/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(executable
2+
(name diff_parsers))

0 commit comments

Comments
 (0)