@@ -45,8 +45,6 @@ open Parsetree
45
45
module Error = struct
46
46
type malformed_extension =
47
47
| Has_payload of payload
48
- | Wrong_arguments of (Asttypes .arg_label * expression ) list
49
- | Wrong_tuple of pattern list
50
48
51
49
type error =
52
50
| Malformed_extension of string list * malformed_extension
@@ -76,23 +74,6 @@ let report_error ~loc = function
76
74
" @[Modular extension nodes are not allowed to have a payload,@ \
77
75
but \" %s\" does@]"
78
76
name
79
- | Wrong_arguments arguments ->
80
- Location. errorf
81
- ~loc
82
- " @[Expression modular extension nodes must be applied to exactly@ \
83
- one unlabeled argument, but \" %s\" was applied to@ %s@]"
84
- name
85
- (match arguments with
86
- | [Labelled _, _] -> " a labeled argument"
87
- | [Optional _, _] -> " an optional argument"
88
- | _ -> Int. to_string (List. length arguments) ^ " arguments" )
89
- | Wrong_tuple patterns ->
90
- Location. errorf
91
- ~loc
92
- " @[Pattern modular extension nodes must be the first component of@ \
93
- a pair, but \" %s\" was the first component of a %d-tuple@]"
94
- name
95
- (1 + List. length patterns)
96
77
end
97
78
| Unknown_extension name ->
98
79
Location. errorf
@@ -147,12 +128,6 @@ module type AST_parameters = sig
147
128
[Parsetree.expression_desc]) *)
148
129
type ast_desc
149
130
150
- (* * The type of the subterms that occur in the "body" slot of an extension
151
- use. This may just be [ast], but e.g. for expressions, we use function
152
- applications, and the terms that a function is applied to contain label
153
- information. *)
154
- type raw_body
155
-
156
131
(* * The name for this syntactic category in the plural form; used for error
157
132
messages *)
158
133
val plural : string
@@ -180,19 +155,11 @@ module type AST_parameters = sig
180
155
181
156
(* * Given an AST node, check if it's of the special syntactic form indicating
182
157
that this is a language extension (as created by [make_extension_node]),
183
- split it back up into the extension node and the possible body terms .
158
+ split it back up into the extension node and the possible body.
184
159
Doesn't do any checking about the name/format of the extension or the
185
160
possible body terms (see [AST.match_extension]). Partial inverse of
186
161
[make_extension_use]. *)
187
- val match_extension_use : ast -> (extension * raw_body list ) option
188
-
189
- (* * Check if a [raw_body] term is legal to use as a body *)
190
- val validate_extension_body : raw_body -> ast option
191
-
192
- (* * The error to throw when the list of possible body terms is wrong: either
193
- when the list isn't exactly one term long, or when that single term fails
194
- [validate_extension_body] *)
195
- val malformed_extension : raw_body list -> malformed_extension
162
+ val match_extension_use : ast -> (extension * ast ) option
196
163
end
197
164
198
165
module type AST = sig
@@ -241,23 +208,19 @@ module Make_AST (AST_parameters : AST_parameters) :
241
208
1. The [[%extension.NAME]] extension point has a payload; extensions must
242
209
be empty, so other ppxes can traverse "into" them.
243
210
244
- 2. The [[%extension.NAME]] extension point contains multiple body forms,
245
- or body forms that are "shaped" incorrectly. *)
211
+ 2. The [[%extension.NAME]] extension point contains
212
+ body forms that are "shaped" incorrectly. *)
246
213
let match_extension ast =
247
214
match match_extension_use ast with
248
- | Some (({txt = ext_name ; loc = ext_loc } , ext_payload ), body_list ) ->
215
+ | Some (({txt = ext_name ; loc = ext_loc } , ext_payload ), body ) ->
249
216
begin
250
217
match String. split_on_char '.' ext_name with
251
218
| "extension" :: names when uniformly_handled_extension names -> begin
252
219
let raise_malformed err =
253
220
raise (Error (ext_loc, Malformed_extension (names, err)))
254
221
in
255
222
match ext_payload with
256
- | PStr [] -> begin
257
- match List. map validate_extension_body body_list with
258
- | [Some body] -> Some (names, body)
259
- | _ -> raise_malformed (malformed_extension body_list)
260
- end
223
+ | PStr [] -> Some (names, body)
261
224
| _ -> raise_malformed (Has_payload ext_payload)
262
225
end
263
226
| _ -> None
269
232
module Expression = Make_AST (struct
270
233
type ast = expression
271
234
type ast_desc = expression_desc
272
- type raw_body = Asttypes .arg_label * expression (* Function arguments *)
273
235
274
236
let plural = " expressions"
275
237
@@ -284,23 +246,17 @@ module Expression = Make_AST(struct
284
246
285
247
let match_extension_use expr =
286
248
match expr.pexp_desc with
287
- | Pexp_apply ({pexp_desc = Pexp_extension ext ; _} , arguments ) ->
288
- Some (ext, arguments)
249
+ | Pexp_apply ({pexp_desc = Pexp_extension ext; _},
250
+ [Asttypes. Nolabel , body]) ->
251
+ Some (ext, body)
289
252
| _ ->
290
253
None
291
-
292
- let validate_extension_body = function
293
- | Asttypes. Nolabel , body -> Some body
294
- | _ , _ -> None
295
-
296
- let malformed_extension args = Wrong_arguments args
297
254
end )
298
255
299
256
(* * Patterns; embedded as [[%extension.EXTNAME], BODY]. *)
300
257
module Pattern = Make_AST (struct
301
258
type ast = pattern
302
259
type ast_desc = pattern_desc
303
- type raw_body = pattern
304
260
305
261
let plural = " patterns"
306
262
@@ -315,13 +271,10 @@ module Pattern = Make_AST(struct
315
271
316
272
let match_extension_use pat =
317
273
match pat.ppat_desc with
318
- | Ppat_tuple ({ppat_desc = Ppat_extension ext ; _} :: patterns ) ->
319
- Some (ext, patterns )
274
+ | Ppat_tuple ([ {ppat_desc = Ppat_extension ext ; _} ; pattern ] ) ->
275
+ Some (ext, pattern )
320
276
| _ ->
321
277
None
322
-
323
- let validate_extension_body = Option. some
324
- let malformed_extension pats = Wrong_tuple pats
325
278
end )
326
279
327
280
(* *****************************************************************************)
0 commit comments