File tree Expand file tree Collapse file tree 8 files changed +31
-15
lines changed Expand file tree Collapse file tree 8 files changed +31
-15
lines changed Original file line number Diff line number Diff line change 44
55- Handle the error-blocks syntax (#439 , @jonludlam , @gpetiot )
66- Allow execution of included OCaml code blocks (#446 , @panglesd )
7+ - Make MDX compatible with OCaml 5.2 (#448 , @gpetiot )
78
89#### Fixed
910
Original file line number Diff line number Diff line change @@ -177,8 +177,7 @@ let pp_contents ?syntax:_ ppf t =
177177
178178let rec error_padding = function
179179 | [] -> []
180- | [ (`Output _ as o); `Output padding ] when Util.String. all_blank padding ->
181- [ o ]
180+ | [ o; `Output padding ] when Util.String. all_blank padding -> [ o ]
182181 | x :: xs ->
183182 let xs = error_padding xs in
184183 x :: xs
Original file line number Diff line number Diff line change @@ -280,3 +280,19 @@ let get_id_opt = function
280280#if OCAML_VERSION > = (5 , 1 , 0 )
281281 | Path. Pextra_ty _ -> None
282282#endif
283+
284+ let mk_fun loc exp =
285+ let punit =
286+ Ast_helper.Pat. construct (Location. mkloc (Longident. Lident " ()" ) loc) None
287+ in
288+ let label = Asttypes. Nolabel in
289+ let default = None in
290+ #if OCAML_VERSION > = (5 , 2 , 0 )
291+ let param =
292+ { Parsetree. pparam_loc= loc
293+ ; pparam_desc= Pparam_val (label, default, punit) }
294+ in
295+ Ast_helper.Exp. function_ [param] None (Pfunction_body exp)
296+ #else
297+ Ast_helper.Exp. fun_ label default punit exp
298+ #endif
Original file line number Diff line number Diff line change @@ -69,3 +69,6 @@ val execute_phrase :
6969val redirect_directive : string -> string
7070val get_id_in_path : Path .t -> Ident .t
7171val get_id_opt : Path .t -> Ident .t option
72+
73+ val mk_fun : Location .t -> Parsetree .expression -> Parsetree .expression
74+ (* * [mk_fun loc e] produces [fun () -> e]. *)
Original file line number Diff line number Diff line change @@ -196,13 +196,10 @@ module Rewrite = struct
196196 let preload = None in
197197 let open Ast_helper in
198198 let rewrite loc e =
199- let punit =
200- Pat. construct (Location. mkloc (Longident. Lident " ()" ) loc) None
201- in
202199 with_default_loc loc @@ fun () ->
203200 Exp. apply
204201 (Exp. ident (Location. mkloc runner loc))
205- [ (Asttypes. Nolabel , Exp. fun_ Asttypes. Nolabel None punit e) ]
202+ [ (Asttypes. Nolabel , Compat_top. mk_fun loc e) ]
206203 in
207204 { typ; rewrite; witness; preload }
208205
Original file line number Diff line number Diff line change 11It is possible to use ellipsis (` ... ` ) in the error blocks attached to OCaml blocks, here it is useful as the error message depends on the OCaml version:
22
3- ``` ocaml
3+ ``` ocaml version<5.2
44module Counter: Irmin.Contents.S with type t = int64 = struct
55 type t = int64
66 let t = Irmin.Type.int64
Original file line number Diff line number Diff line change @@ -14,16 +14,16 @@ Error: This 'struct' might be unmatched
1414```
1515
1616
17- ``` ocaml version>=4.08
17+ ``` ocaml version>=5.2
1818module Counter: Irmin.Contents.S with type t = int64 = struct
1919 type t = int64
2020 let t = Irmin.Type.int64
2121```
2222``` mdx-error
2323Line 4, characters 3-3:
24- Error: Syntax error: ' end' expected
24+ Error: Syntax error: end expected
2525Line 1, characters 56-62:
26- This ' struct' might be unmatched
26+ This struct might be unmatched
2727```
2828
2929
4444```
4545``` mdx-error
4646Line 4, characters 3-3:
47- Error: Syntax error: ' end' expected
47+ Error: Syntax error: end expected
4848Line 1, characters 56-62:
49- This ' struct' might be unmatched
49+ This struct might be unmatched
5050```
Original file line number Diff line number Diff line change @@ -14,16 +14,16 @@ Error: This 'struct' might be unmatched
1414```
1515
1616
17- ```ocaml version>=4.08
17+ ```ocaml version>=5.2
1818module Counter: Irmin.Contents.S with type t = int64 = struct
1919 type t = int64
2020 let t = Irmin.Type.int64
2121```
2222```mdx-error
2323Line 4, characters 3-3:
24- Error: Syntax error: ' end' expected
24+ Error: Syntax error: end expected
2525Line 1, characters 56-62:
26- This ' struct' might be unmatched
26+ This struct might be unmatched
2727```
2828
2929
You can’t perform that action at this time.
0 commit comments