@@ -41,8 +41,6 @@ open Jane_syntax_parsing
41
41
future syntax features to remember to do this wrapping.
42
42
*)
43
43
44
- module With_attributes = With_attributes
45
-
46
44
(* * List and array comprehensions *)
47
45
module Comprehensions = struct
48
46
let feature : Feature.t = Language_extension Comprehensions
@@ -94,9 +92,7 @@ module Comprehensions = struct
94
92
v}
95
93
*)
96
94
97
- let comprehension_expr names x =
98
- Expression. wrap_desc ~info: [] ~loc: x.pexp_loc @@
99
- Expression. make_jane_syntax feature names x
95
+ let comprehension_expr names x = Expression. make_jane_syntax feature names x
100
96
101
97
(* * First, we define how to go from the nice AST to the OCaml AST; this is
102
98
the [expr_of_...] family of expressions, culminating in
@@ -143,9 +139,9 @@ module Comprehensions = struct
143
139
clauses
144
140
(comprehension_expr [" body" ] body)))
145
141
146
- let expr_of ~loc cexpr =
142
+ let expr_of ~loc ~ attrs cexpr =
147
143
(* See Note [Wrapping with make_entire_jane_syntax] *)
148
- Expression. make_entire_jane_syntax ~loc feature (fun () ->
144
+ let expr = Expression. make_entire_jane_syntax ~loc feature (fun () ->
149
145
match cexpr with
150
146
| Cexp_list_comprehension comp ->
151
147
expr_of_comprehension ~type_: [" list" ] comp
@@ -157,6 +153,8 @@ module Comprehensions = struct
157
153
| Immutable -> " immutable"
158
154
]
159
155
comp)
156
+ in
157
+ { expr with pexp_attributes = expr.pexp_attributes @ attrs }
160
158
161
159
(* * Then, we define how to go from the OCaml AST to the nice AST; this is
162
160
the [..._of_expr] family of expressions, culminating in
@@ -286,22 +284,22 @@ module Immutable_arrays = struct
286
284
287
285
let feature : Feature.t = Language_extension Immutable_arrays
288
286
289
- let expr_of ~loc = function
287
+ let expr_of ~loc ~ attrs = function
290
288
| Iaexp_immutable_array elts ->
291
289
(* See Note [Wrapping with make_entire_jane_syntax] *)
292
290
Expression. make_entire_jane_syntax ~loc feature (fun () ->
293
- Ast_helper.Exp. array elts)
291
+ Ast_helper.Exp. array ~attrs elts)
294
292
295
293
(* Returns remaining unconsumed attributes *)
296
294
let of_expr expr = match expr.pexp_desc with
297
295
| Pexp_array elts -> Iaexp_immutable_array elts, expr.pexp_attributes
298
296
| _ -> failwith " Malformed immutable array expression"
299
297
300
- let pat_of ~loc = function
298
+ let pat_of ~loc ~ attrs = function
301
299
| Iapat_immutable_array elts ->
302
300
(* See Note [Wrapping with make_entire_jane_syntax] *)
303
301
Pattern. make_entire_jane_syntax ~loc feature (fun () ->
304
- Ast_helper.Pat. array elts)
302
+ Ast_helper.Pat. array ~attrs elts)
305
303
306
304
(* Returns remaining unconsumed attributes *)
307
305
let of_pat pat = match pat.ppat_desc with
@@ -351,10 +349,10 @@ module Strengthen = struct
351
349
the [(module M)] is a [Pmty_alias]. This isn't syntax we can write, but
352
350
[(module M)] can be the inferred type for [M], so this should be fine. *)
353
351
354
- let mty_of ~loc { mty; mod_id } =
352
+ let mty_of ~loc ~ attrs { mty; mod_id } =
355
353
(* See Note [Wrapping with make_entire_jane_syntax] *)
356
354
Module_type. make_entire_jane_syntax ~loc feature (fun () ->
357
- Ast_helper.Mty. functor_ (Named (Location. mknoloc None , mty))
355
+ Ast_helper.Mty. functor_ ~attrs (Named (Location. mknoloc None , mty))
358
356
(Ast_helper.Mty. alias mod_id))
359
357
360
358
(* Returns remaining unconsumed attributes *)
@@ -404,15 +402,15 @@ module Unboxed_constants = struct
404
402
| Float (x , suffix ) -> Pconst_float (x, suffix)
405
403
| Integer (x , suffix ) -> Pconst_integer (x, Some suffix)
406
404
407
- let expr_of ~loc t =
405
+ let expr_of ~loc ~ attrs t =
408
406
let constant = constant_of t in
409
407
Expression. make_entire_jane_syntax ~loc feature (fun () ->
410
- Ast_helper.Exp. constant constant)
408
+ Ast_helper.Exp. constant ~attrs constant)
411
409
412
- let pat_of ~loc t =
410
+ let pat_of ~loc ~ attrs t =
413
411
let constant = constant_of t in
414
412
Pattern. make_entire_jane_syntax ~loc feature (fun () ->
415
- Ast_helper.Pat. constant constant)
413
+ Ast_helper.Pat. constant ~attrs constant)
416
414
end
417
415
418
416
(* *****************************************************************************)
@@ -463,10 +461,10 @@ module Expression = struct
463
461
464
462
let of_ast = Expression. make_of_ast ~of_ast_internal
465
463
466
- let expr_of ~loc = function
467
- | Jexp_comprehension x -> Comprehensions. expr_of ~loc x
468
- | Jexp_immutable_array x -> Immutable_arrays. expr_of ~loc x
469
- | Jexp_unboxed_constant x -> Unboxed_constants. expr_of ~loc x
464
+ let expr_of ~loc ~ attrs = function
465
+ | Jexp_comprehension x -> Comprehensions. expr_of ~loc ~attrs x
466
+ | Jexp_immutable_array x -> Immutable_arrays. expr_of ~loc ~attrs x
467
+ | Jexp_unboxed_constant x -> Unboxed_constants. expr_of ~loc ~attrs x
470
468
end
471
469
472
470
module Pattern = struct
@@ -485,9 +483,9 @@ module Pattern = struct
485
483
486
484
let of_ast = Pattern. make_of_ast ~of_ast_internal
487
485
488
- let pat_of ~loc = function
489
- | Jpat_immutable_array x -> Immutable_arrays. pat_of ~loc x
490
- | Jpat_unboxed_constant x -> Unboxed_constants. pat_of ~loc x
486
+ let pat_of ~loc ~ attrs = function
487
+ | Jpat_immutable_array x -> Immutable_arrays. pat_of ~loc ~attrs x
488
+ | Jpat_unboxed_constant x -> Unboxed_constants. pat_of ~loc ~attrs x
491
489
end
492
490
493
491
module Module_type = struct
0 commit comments