-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathsync_stdlib_docs
executable file
·167 lines (143 loc) · 7.08 KB
/
sync_stdlib_docs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
#**************************************************************************
#* *
#* OCaml *
#* *
#* John Whitington *
#* *
#* Copyright 2020 Institut National de Recherche en Informatique et *
#* en automatique *
#* *
#* All rights reserved. This file is distributed under the terms of *
#* the GNU Lesser General Public License version 2.1, with the *
#* special exception on linking described in the file LICENSE. *
#* *
#**************************************************************************
#Allow to be run from outside tools/
cd $(dirname "$0")/..
if [[ ! -d stdlib || ! -d otherlibs ]] ; then
echo 'Cannot find the stdlib and otherlibs directories' >&2
exit 1
fi
#Removes a label, i.e a space, a variable name, followed by a colon followed by
#an alphabetic character or ( or '. This should avoid altering the contents of
#comments.
LABREGEX="s/ [a-z_]+:([a-z\('])/ \1/g"
#A second, slightly different round sometimes required to deal with f:(key:key
LABLABREGEX="s/\([a-z_]+:([a-z\('])/\(\1/g"
#Remove a tilde if it is followed by a label name and a space or closing
#OCamldoc code section with ]
TILDEREGEX="s/ ~([a-z_]+(?=[ \]]))/ \1/g"
#Indent a non-blank line by two characters, for moreLabels templates
INDENTREGEX="s/^(.+)$/ \1/m"
#Remove Labels suffix in examples
LABELSDOTARGREGEX="s/([A-Z][a-z_]*)Labels\.(.*)~[a-z]+:/\1Labels.\2/g"
LABELSDOTREGEX="s/([A-Z][a-z_]*)Labels\./\1./g"
#Stdlib
perl -p -e "$LABREGEX" stdlib/listLabels.mli > stdlib/list.temp.mli
perl -p -e "$LABREGEX" stdlib/arrayLabels.mli > stdlib/array.temp.mli
perl -p -e "$LABREGEX" stdlib/iarrayLabels.mli > stdlib/iarray.temp.mli
perl -p -e "$LABREGEX" stdlib/stringLabels.mli > stdlib/string.temp.mli
perl -p -e "$LABREGEX" stdlib/bytesLabels.mli > stdlib/bytes.temp.mli
#Stdlib tildes
perl -p -e "$TILDEREGEX" stdlib/list.temp.mli > stdlib/list.mli
perl -p -e "$TILDEREGEX" stdlib/array.temp.mli > stdlib/array.2temp.mli
perl -p -e "$TILDEREGEX" stdlib/iarray.temp.mli > stdlib/iarray.2temp.mli
perl -p -e "$TILDEREGEX" stdlib/string.temp.mli > stdlib/string.mli
perl -p -e "$TILDEREGEX" stdlib/bytes.temp.mli > stdlib/bytes.mli
# Array
perl -p -e "$LABELSDOTARGREGEX" stdlib/array.2temp.mli > stdlib/array.3temp.mli
perl -p -e "$LABELSDOTREGEX" stdlib/array.3temp.mli > stdlib/array.mli
perl -p -e "$LABELSDOTARGREGEX" stdlib/iarray.2temp.mli > stdlib/iarray.3temp.mli
perl -p -e "$LABELSDOTREGEX" stdlib/iarray.3temp.mli > stdlib/iarray.mli
#FloatArrayLabels
perl -p -e "$LABREGEX" \
stdlib/templates/floatarraylabeled.template.mli > \
stdlib/templates/floatarrayunlabeled.temp.mli
perl -p -e "$TILDEREGEX" stdlib/templates/floatarrayunlabeled.temp.mli > \
stdlib/templates/floatarrayunlabeled.2temp.mli
perl -p -e "$LABELSDOTARGREGEX" \
stdlib/templates/floatarrayunlabeled.2temp.mli > \
stdlib/templates/floatarrayunlabeled.3temp.mli
perl -p -e "$LABELSDOTREGEX" stdlib/templates/floatarrayunlabeled.3temp.mli > \
stdlib/templates/floatarrayunlabeled.4temp.mli
perl -p -e "$INDENTREGEX" stdlib/templates/floatarraylabeled.template.mli > \
stdlib/templates/fal.indented.temp.mli
perl -p -e "$INDENTREGEX" stdlib/templates/floatarrayunlabeled.4temp.mli > \
stdlib/templates/fau.indented.temp.mli
perl -p -e\
's/FLOATARRAYLAB/`tail -n +17 stdlib\/templates\/fal.indented.temp.mli`/e' \
stdlib/templates/float.template.mli > \
stdlib/templates/float.template.temp.mli
perl -p -e\
's/FLOATARRAY/`tail -n +17 stdlib\/templates\/fau.indented.temp.mli`/e' \
stdlib/templates/float.template.temp.mli > \
stdlib/float.mli
#MoreLabels
perl -p -e "$LABREGEX" \
stdlib/templates/hashtbl.template.mli > stdlib/hashtbl.temp.mli
perl -p -e "$LABLABREGEX" \
stdlib/hashtbl.temp.mli > stdlib/hashtbl.2temp.mli
perl -p -e "$LABREGEX" \
stdlib/templates/map.template.mli > stdlib/map.temp.mli
perl -p -e "$LABLABREGEX" \
stdlib/map.temp.mli > stdlib/map.2temp.mli
perl -p -e "$LABREGEX" \
stdlib/templates/set.template.mli > stdlib/set.temp.mli
perl -p -e "$LABLABREGEX" \
stdlib/set.temp.mli > stdlib/set.2temp.mli
#MoreLabels tildes
perl -p -e "$TILDEREGEX" stdlib/hashtbl.2temp.mli > stdlib/hashtbl.mli
perl -p -e "$TILDEREGEX" stdlib/map.2temp.mli > stdlib/map.mli
perl -p -e "$TILDEREGEX" stdlib/set.2temp.mli > stdlib/set.mli
#Indent the labeled modules
perl -p -e "$INDENTREGEX" stdlib/templates/hashtbl.template.mli > \
stdlib/templates/hashtbl.template.temp.mli
perl -p -e "$INDENTREGEX" stdlib/templates/map.template.mli > \
stdlib/templates/map.template.temp.mli
perl -p -e "$INDENTREGEX" stdlib/templates/set.template.mli > \
stdlib/templates/set.template.temp.mli
#Substitute the labeled modules in to moreLabels.mli
perl -p -e\
's/HASHTBL/`tail -n +19 stdlib\/templates\/hashtbl.template.temp.mli`/e' \
stdlib/templates/moreLabels.template.mli > stdlib/moreLabels.temp.mli
perl -p -e 's/MAP/`tail -n +19 stdlib\/templates\/map.template.temp.mli`/e' \
stdlib/moreLabels.temp.mli > stdlib/moreLabels.2temp.mli
perl -p -e 's/SET/`tail -n +19 stdlib\/templates\/set.template.temp.mli`/e' \
stdlib/moreLabels.2temp.mli > stdlib/moreLabels.mli
#Fix up with templates in tools/unlabel-patches
perl -p -e "s/type statistics =/type statistics = Hashtbl\.statistics =/" \
stdlib/moreLabels.mli > stdlib/moreLabels.temp.mli
perl -p -e "s/type \(!'a, !'b\) t/type \(!'a, !'b\) t = \('a, 'b) Hashtbl.t/" \
stdlib/moreLabels.temp.mli > stdlib/moreLabels.2temp.mli
perl -p -e\
"s/module Make \(H : HashedType\) : S with type key = H.t\
/`cat tools/unlabel-patches/1.mli`/" \
stdlib/moreLabels.2temp.mli > stdlib/moreLabels.3temp.mli
perl -p -e\
"s/module MakeSeeded \(H : SeededHashedType\) : SeededS with type key = H.t\
/`cat tools/unlabel-patches/2.mli`/" \
stdlib/moreLabels.3temp.mli > stdlib/moreLabels.4temp.mli
perl -p -e\
"s/module Make \(Ord : OrderedType\) : S with type key = Ord.t\
/`cat tools/unlabel-patches/3.mli`/" \
stdlib/moreLabels.4temp.mli > stdlib/moreLabels.5temp.mli
perl -p -e\
"s/module Make \(Ord : OrderedType\) : S with type elt = Ord.t\
/`cat tools/unlabel-patches/4.mli`/" \
stdlib/moreLabels.5temp.mli > stdlib/moreLabels.mli
#Unix
perl -p -e "$LABREGEX" \
otherlibs/unix/unixLabels.mli > otherlibs/unix/unix.temp.mli
#Tildes
perl -p -e "$TILDEREGEX" \
otherlibs/unix/unix.temp.mli > otherlibs/unix/unix.2temp.mli
#Remove type equivalences from unix.mli
perl -p -e 's/ = Unix.[a-z_]+//' \
otherlibs/unix/unix.2temp.mli > otherlibs/unix/unix.3temp.mli
perl -p -e 's/ = Unix.LargeFile.stats//' \
otherlibs/unix/unix.3temp.mli > otherlibs/unix/unix.mli
#Clean up
rm -f stdlib/*temp.mli
rm -f otherlibs/unix/*temp.mli
rm -f stdlib/templates/*temp.mli