@@ -3,13 +3,25 @@ open! Import
33module Format = Stdlib. Format
44module Filename = Stdlib. Filename
55
6- (* TODO: make the "deriving." depend on the matching attribute name. *)
6+ let allow_deriving_end = ref true
7+
8+ (* TODO: make the "deriving." or other prefix depend on the matching attribute name. *)
79let end_marker_sig =
8- Attribute.Floating. declare " deriving .end" Signature_item
10+ Attribute.Floating. declare " ppxlib.inline .end" Signature_item
911 Ast_pattern. (pstr nil)
1012 ()
1113
1214let end_marker_str =
15+ Attribute.Floating. declare " ppxlib.inline.end" Structure_item
16+ Ast_pattern. (pstr nil)
17+ ()
18+
19+ let deprecated_end_marker_sig =
20+ Attribute.Floating. declare " deriving.end" Signature_item
21+ Ast_pattern. (pstr nil)
22+ ()
23+
24+ let deprecated_end_marker_str =
1325 Attribute.Floating. declare " deriving.end" Structure_item
1426 Ast_pattern. (pstr nil)
1527 ()
@@ -24,6 +36,7 @@ module Make (M : sig
2436
2537 val get_loc : t -> Location .t
2638 val end_marker : (t , unit ) Attribute.Floating .t
39+ val deprecated_end_marker : (t , unit ) Attribute.Floating .t
2740
2841 module Transform (T : T1 ) : sig
2942 val apply :
@@ -51,10 +64,27 @@ struct
5164 [] )
5265 | x :: l -> (
5366 match Attribute.Floating. convert_res [ M. end_marker ] x with
54- | Ok None -> loop (x :: acc) l
5567 | Ok (Some () ) -> Ok (List. rev acc, (M. get_loc x).loc_start)
5668 | Error e -> Error e
57- | exception Failure _ -> loop (x :: acc) l)
69+ | (exception Failure _ ) | Ok None -> (
70+ match
71+ Attribute.Floating. convert_res [ M. deprecated_end_marker ] x
72+ with
73+ | Ok (Some () ) ->
74+ if ! allow_deriving_end then
75+ Ok (List. rev acc, (M. get_loc x).loc_start)
76+ else
77+ Error
78+ ( Location.Error. createf ~loc: (M. get_loc x)
79+ " ppxlib: [@@@@@@%s] is deprecated, please use \
80+ [@@@@@@%s]. If you need the deprecated attribute \
81+ temporarily, pass [-allow-deriving-end] to the ppx \
82+ driver)."
83+ (Attribute.Floating. name M. deprecated_end_marker)
84+ (Attribute.Floating. name M. end_marker),
85+ [] )
86+ | Error e -> Error e
87+ | (exception Failure _ ) | Ok None -> loop (x :: acc) l))
5888 in
5989 loop [] l
6090
@@ -170,6 +200,7 @@ module Str = Make (struct
170200
171201 let get_loc x = x.pstr_loc
172202 let end_marker = end_marker_str
203+ let deprecated_end_marker = deprecated_end_marker_str
173204
174205 module Transform (T : T1 ) = struct
175206 let apply o = o#structure_item
@@ -188,6 +219,7 @@ module Sig = Make (struct
188219
189220 let get_loc x = x.psig_loc
190221 let end_marker = end_marker_sig
222+ let deprecated_end_marker = deprecated_end_marker_sig
191223
192224 module Transform (T : T1 ) = struct
193225 let apply o = o#signature_item
0 commit comments