@@ -78,7 +78,7 @@ let emitFromLoc ~loc ~type_ emitter =
78
78
let posStart, posEnd = locToPositions loc in
79
79
emitter |> emitFromPos posStart posEnd ~type_
80
80
81
- let emitLongident ~ backwards ~ pos ~ jsx ~lid ~debug emitter =
81
+ let emitLongident ?( backwards = false ) ?( jsx = false ) ~ pos ~lid ~debug emitter =
82
82
let rec flatten acc lid =
83
83
match lid with
84
84
| Longident. Lident txt -> txt :: acc
@@ -115,13 +115,13 @@ let emitLongident ~backwards ~pos ~jsx ~lid ~debug emitter =
115
115
116
116
let emitVariable ~id ~debug ~loc emitter =
117
117
emitter
118
- |> emitLongident ~backwards: false
118
+ |> emitLongident
119
119
~pos: (Utils. tupleOfLexing loc.Location. loc_start)
120
- ~jsx: false ~ lid: (Longident. Lident id) ~debug
120
+ ~lid: (Longident. Lident id) ~debug
121
121
122
122
let emitJsxOpen ~lid ~debug ~loc emitter =
123
123
emitter
124
- |> emitLongident ~backwards: false
124
+ |> emitLongident
125
125
~pos: (Utils. tupleOfLexing loc.Location. loc_start)
126
126
~lid ~jsx: true ~debug
127
127
@@ -163,9 +163,7 @@ let parser ~debug ~emitter ~path =
163
163
match e.pexp_desc with
164
164
| Pexp_ident {txt = lid ; loc} ->
165
165
emitter
166
- |> emitLongident ~backwards: false
167
- ~pos: (Utils. tupleOfLexing loc.loc_start)
168
- ~lid ~jsx: false ~debug ;
166
+ |> emitLongident ~pos: (Utils. tupleOfLexing loc.loc_start) ~lid ~debug ;
169
167
Ast_mapper. default_mapper.expr mapper e
170
168
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
171
169
when Res_parsetree_viewer. isJsxExpression e ->
@@ -206,9 +204,69 @@ let parser ~debug ~emitter ~path =
206
204
Ast_mapper. default_mapper.expr mapper e
207
205
| _ -> Ast_mapper. default_mapper.expr mapper e
208
206
in
207
+ let module_expr (mapper : Ast_mapper.mapper ) (me : Parsetree.module_expr ) =
208
+ match me.pmod_desc with
209
+ | Pmod_ident {txt = lid ; loc} ->
210
+ emitter
211
+ |> emitLongident ~pos: (Utils. tupleOfLexing loc.loc_start) ~lid ~debug ;
212
+ Ast_mapper. default_mapper.module_expr mapper me
213
+ | _ -> Ast_mapper. default_mapper.module_expr mapper me
214
+ in
215
+ let module_binding (mapper : Ast_mapper.mapper )
216
+ (mb : Parsetree.module_binding ) =
217
+ emitter
218
+ |> emitLongident
219
+ ~pos: (Utils. tupleOfLexing mb.pmb_name.loc.loc_start)
220
+ ~lid: (Longident. Lident mb.pmb_name.txt) ~debug ;
221
+ Ast_mapper. default_mapper.module_binding mapper mb
222
+ in
223
+ let module_declaration (mapper : Ast_mapper.mapper )
224
+ (md : Parsetree.module_declaration ) =
225
+ emitter
226
+ |> emitLongident
227
+ ~pos: (Utils. tupleOfLexing md.pmd_name.loc.loc_start)
228
+ ~lid: (Longident. Lident md.pmd_name.txt) ~debug ;
229
+ Ast_mapper. default_mapper.module_declaration mapper md
230
+ in
231
+ let module_type (mapper : Ast_mapper.mapper ) (mt : Parsetree.module_type ) =
232
+ match mt.pmty_desc with
233
+ | Pmty_ident {txt = lid ; loc} ->
234
+ emitter
235
+ |> emitLongident ~pos: (Utils. tupleOfLexing loc.loc_start) ~lid ~debug ;
236
+ Ast_mapper. default_mapper.module_type mapper mt
237
+ | _ -> Ast_mapper. default_mapper.module_type mapper mt
238
+ in
239
+ let module_type_declaration (mapper : Ast_mapper.mapper )
240
+ (mtd : Parsetree.module_type_declaration ) =
241
+ emitter
242
+ |> emitLongident
243
+ ~pos: (Utils. tupleOfLexing mtd.pmtd_name.loc.loc_start)
244
+ ~lid: (Longident. Lident mtd.pmtd_name.txt) ~debug ;
245
+ Ast_mapper. default_mapper.module_type_declaration mapper mtd
246
+ in
247
+ let open_description (mapper : Ast_mapper.mapper )
248
+ (od : Parsetree.open_description ) =
249
+ emitter
250
+ |> emitLongident
251
+ ~pos: (Utils. tupleOfLexing od.popen_lid.loc.loc_start)
252
+ ~lid: od.popen_lid.txt ~debug ;
253
+ Ast_mapper. default_mapper.open_description mapper od
254
+ in
209
255
210
256
let mapper =
211
- {Ast_mapper. default_mapper with expr; pat; typ; type_declaration}
257
+ {
258
+ Ast_mapper. default_mapper with
259
+ expr;
260
+ module_declaration;
261
+ module_binding;
262
+ module_expr;
263
+ module_type;
264
+ module_type_declaration;
265
+ open_description;
266
+ pat;
267
+ typ;
268
+ type_declaration;
269
+ }
212
270
in
213
271
214
272
if Filename. check_suffix path " .res" then (
0 commit comments