Skip to content

Commit 52a7b7c

Browse files
authored
Merge pull request #172 from kit-ty-kate/ocaml-5.3
Add OCaml 5.3 support
2 parents 7123ea8 + 2cfbd39 commit 52a7b7c

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

.github/workflows/workflow.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
os:
1313
- ubuntu-latest
1414
ocaml-version:
15-
- 5.1.0~rc1
15+
- 5.3.0~beta2
16+
- 5.2.0
17+
- 5.1.1
1618
- 5.0.0
1719
- 4.14.0
1820
- 4.13.1

libs/indexBuild.ml

+19-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type parents = (string list * t Lazy.t) list
3131

3232
open IndexMisc
3333

34+
#if OCAML_VERSION >= (5,3,0)
35+
module Printtyp = Out_type
36+
#endif
37+
3438
let orig_file_name = function
3539
| Cmt f | Cmti f | Cmi f -> f
3640

@@ -246,7 +250,11 @@ let qualify_ty (parents:parents) ty =
246250
Otyp_object (List.map (fun (str,ty) -> str, aux ty) strtylist, blopt)
247251
#endif
248252
| Otyp_record (strbltylist) ->
253+
#if OCAML_VERSION >= (5,3,0)
254+
Otyp_record (List.map (fun {olab_name; olab_mut; olab_type} -> {olab_name; olab_mut; olab_type = aux olab_type}) strbltylist)
255+
#else
249256
Otyp_record (List.map (fun (str,bl,ty) -> str, bl, aux ty) strbltylist)
257+
#endif
250258
| Otyp_stuff str -> Otyp_stuff str
251259
| Otyp_sum (strtylisttyoptlist) ->
252260
Otyp_sum
@@ -420,7 +428,9 @@ let doc_of_attributes attrs =
420428
| _, PStr [{pstr_desc = Pstr_eval ({pexp_desc},_)}] ->
421429
#endif
422430
(match pexp_desc with
423-
#if OCAML_VERSION >= (4,11,0)
431+
#if OCAML_VERSION >= (5,3,0)
432+
| Pexp_constant {pconst_desc = Pconst_string (s,_,_); _} -> Some s
433+
#elif OCAML_VERSION >= (4,11,0)
424434
| Pexp_constant (Pconst_string (s,_,_)) -> Some s
425435
#elif OCAML_VERSION >= (4,03,0)
426436
| Pexp_constant (Pconst_string (s,_)) -> Some s
@@ -533,12 +543,20 @@ let trie_of_type_decl ?comments info ty_decl =
533543
Outcometree.Otyp_record (
534544
List.map
535545
(fun l ->
546+
#if OCAML_VERSION >= (5,3,0)
547+
{
548+
Outcometree.olab_name = Ident.name l.Types.ld_id;
549+
olab_mut = l.ld_mutable;
550+
olab_type = Printtyp.tree_of_typexp Printtyp.Type l.ld_type;
551+
}
552+
#else
536553
(Ident.name l.Types.ld_id,
537554
l.ld_mutable = Mutable,
538555
#if OCAML_VERSION >= (4,14,0)
539556
Printtyp.tree_of_typexp Printtyp.Type l.ld_type)
540557
#else
541558
Printtyp.tree_of_typexp false l.ld_type)
559+
#endif
542560
#endif
543561
)
544562
params)

libs/indexOut.ml

+23-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414

1515
open IndexTypes
1616

17+
#if OCAML_VERSION < (5,3,0)
18+
module Format_doc = struct
19+
let compat = Fun.id
20+
end
21+
#endif
22+
1723
let option_iter opt f = match opt with
1824
| Some x -> f x
1925
| None -> ()
@@ -118,10 +124,18 @@ module IndexFormat = struct
118124
| Otyp_abstract -> Format.fprintf fmt "<abstract>"
119125
| Otyp_manifest (ty,_) -> tydecl fmt ty
120126
| Otyp_record fields ->
127+
#if OCAML_VERSION >= (5,3,0)
128+
let print_field fmt {olab_name; olab_mut; olab_type} =
129+
Format.fprintf fmt "@[<2>%s%s :@ @[%a@]@];"
130+
(match olab_mut with Mutable -> "mutable " | Immutable -> "")
131+
olab_name
132+
(Format_doc.compat !Oprint.out_type) olab_type
133+
#else
121134
let print_field fmt (name, mut, arg) =
122135
Format.fprintf fmt "@[<2>%s%s :@ @[%a@]@];"
123136
(if mut then "mutable " else "") name
124137
!Oprint.out_type arg
138+
#endif
125139
in
126140
Format.fprintf fmt "@[<hv 2>{%a}@]"
127141
(list
@@ -143,52 +157,52 @@ module IndexFormat = struct
143157
else
144158
Format.fprintf fmt "@[<2>%s of@ @[%a@]@]"
145159
name
146-
(list !Oprint.out_type
160+
(list (Format_doc.compat !Oprint.out_type)
147161
(fun fmt () -> Format.fprintf fmt " *@ "))
148162
tyl
149163
| Some ret_type ->
150164
if tyl = [] then
151165
Format.fprintf fmt "@[<2>%s :@ @[%a@]@]" name
152-
!Oprint.out_type ret_type
166+
(Format_doc.compat !Oprint.out_type) ret_type
153167
else
154168
Format.fprintf fmt "@[<2>%s :@ @[%a -> @[%a@]@]@]"
155169
name
156-
(list !Oprint.out_type
170+
(list (Format_doc.compat !Oprint.out_type)
157171
(fun fmt () -> Format.fprintf fmt " *@ "))
158172
tyl
159-
!Oprint.out_type ret_type
173+
(Format_doc.compat !Oprint.out_type) ret_type
160174
in
161175
list print_variant
162176
~left:(fun fmt ->
163177
Format.pp_print_if_newline fmt (); Format.fprintf fmt "| ")
164178
(fun fmt () -> Format.fprintf fmt "@ | ")
165179
fmt constrs
166180
| ty ->
167-
!Oprint.out_type fmt ty
181+
Format_doc.compat !Oprint.out_type fmt ty
168182

169183
let out_ty fmt ty =
170184
let open Outcometree in
171185
match ty with
172186
| Osig_class (_,_,_,ctyp,_)
173187
| Osig_class_type (_,_,_,ctyp,_) ->
174-
!Oprint.out_class_type fmt ctyp
188+
Format_doc.compat !Oprint.out_class_type fmt ctyp
175189
| Osig_typext ({ oext_args = [] }, _) ->
176190
Format.pp_print_char fmt '-'
177191
| Osig_typext ({ oext_args }, _) ->
178192
list ~paren:true
179-
!Oprint.out_type
193+
(Format_doc.compat !Oprint.out_type)
180194
(fun fmt () ->
181195
Format.pp_print_char fmt ','; Format.pp_print_space fmt ())
182196
fmt
183197
oext_args
184198
| Osig_modtype (_,mtyp)
185199
| Osig_module (_,mtyp,_) ->
186-
!Oprint.out_module_type fmt mtyp
200+
Format_doc.compat !Oprint.out_module_type fmt mtyp
187201
#if OCAML_VERSION >= (4,03,0)
188202
| Osig_type ({ otype_type },_) ->
189203
tydecl fmt otype_type
190204
| Osig_value {oval_type} ->
191-
!Oprint.out_type fmt oval_type
205+
Format_doc.compat !Oprint.out_type fmt oval_type
192206
| Osig_ellipsis ->
193207
Format.fprintf fmt "..."
194208
#elif OCAML_VERSION >= (4,02,0)

src/indexMain.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
(** This module contains the run-time for the command-line ocp-index tool *)
1616

17-
1817
open Cmdliner
1918

2019
let common_opts = IndexOptions.common_opts ()
2120

22-
let default_cmd =
21+
let default_cmd =
2322
Term.(ret (const (fun _ -> `Help (`Pager, None)) $ common_opts))
2423

2524
let default_info =
@@ -146,7 +145,7 @@ let complete_cmd =
146145
Cmd.v
147146
(Cmd.info "complete" ~doc ~man)
148147
Term.(const print_compl $ common_opts $ sexpr $ format $ separate $ t)
149-
148+
150149

151150
let type_cmd =
152151
let man = [
@@ -171,7 +170,7 @@ let type_cmd =
171170
Cmd.v
172171
(Cmd.info "type" ~doc ~man)
173172
Term.(const print_ty $ common_opts $ t)
174-
173+
175174

176175
let locate_cmd =
177176
let man = [
@@ -215,7 +214,7 @@ let locate_cmd =
215214
Cmd.v
216215
(Cmd.info "locate" ~doc ~man)
217216
Term.(const print_loc $ common_opts $ interface $ t)
218-
217+
219218

220219
let print_cmd =
221220
let man = [
@@ -252,7 +251,7 @@ let print_cmd =
252251
let doc = "Print information about an identifier with a custom format." in
253252
Cmd.v
254253
(Cmd.info "print" ~doc ~man)
255-
Term.(const print $ common_opts $ query $ format $ separate)
254+
Term.(const print $ common_opts $ query $ format $ separate)
256255

257256
let full_cmd =
258257
Cmd.group ~default:default_cmd default_info

0 commit comments

Comments
 (0)