@@ -270,19 +270,16 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
270270 )
271271 | _ -> default_mapper.signature_item self sigi
272272
273-
273+ let local_module_name =
274+ let v = ref 0 in
275+ fun () ->
276+ incr v ;
277+ " local_" ^ (string_of_int ! v)
274278
275279let structure_item_mapper (self : mapper ) (str : Parsetree.structure_item ) =
276280 match str.pstr_desc with
277- | Pstr_extension ( ({txt = (" bs.raw" | " raw" ) ; loc}, payload), _attrs)
278- ->
279- Ast_exp_handle_external. handle_raw_structure loc payload
280- | Pstr_extension (({txt = (" bs.debugger.chrome" | " debugger.chrome" ) ;loc}, payload),_)
281- ->
282- Location. prerr_warning loc (Preprocessor " this extension can be safely removed" );
283- Ast_structure. dummy_item loc
284281 | Pstr_type (
285- _rf,
282+ _rf, (* FIXME *)
286283 (_ :: _ as tdcls )) (* [ {ptype_attributes} as tdcl ] *) ->
287284 Ast_tdcls. handleTdclsInStru self str tdcls
288285 | Pstr_primitive prim when Ast_attributes. external_needs_to_be_encoded prim.pval_attributes
@@ -341,15 +338,60 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
341338 | _ -> default_mapper.structure_item self str
342339
343340
344-
341+ let rec
342+ structure_mapper (self : mapper ) stru =
343+ match stru with
344+ | [] -> []
345+ | item ::rest ->
346+ let new_x = self.structure_item self item in
347+ match new_x.pstr_desc with
348+ | Pstr_extension (({txt = (" bs.debugger.chrome" | " debugger.chrome" ) ;loc}, _),_)
349+ ->
350+ Location. prerr_warning loc (Preprocessor " this extension can be safely removed" );
351+ (structure_mapper self rest)
352+ | Pstr_extension ( ({txt = (" bs.raw" | " raw" ) ; loc}, payload), _attrs)
353+ ->
354+ Ast_exp_handle_external. handle_raw_structure loc payload :: (structure_mapper self rest)
355+ | Pstr_extension (({txt = " local" ; loc}, payload),_)
356+ ->
357+ begin match payload with
358+ | PStr stru ->
359+ (* check no module, no type allowed *)
360+ (* let stru = self.structure self stru in *)
361+ Ext_list. iter stru Typemod_hide. check;
362+ let local_module_name = local_module_name () in
363+ let open Ast_helper in
364+ Str. module_
365+ ~loc
366+ { pmb_name = {txt = local_module_name; loc};
367+ pmb_expr = {
368+ pmod_desc= Pmod_structure stru;
369+ pmod_loc = loc;
370+ pmod_attributes = [] };
371+ pmb_attributes = Typemod_hide. attrs; pmb_loc = loc} ::
372+ Str. open_ ~loc {
373+ popen_lid = {txt = Lident local_module_name; loc};
374+ popen_override = Override ;
375+ popen_loc = loc;
376+ popen_attributes = []
377+ } :: structure_mapper self rest
378+ | PSig _
379+ | PTyp _
380+ | PPat _ ->
381+ Location. raise_errorf ~loc " local extension is not support"
382+ end
383+ | _ ->
384+ new_x :: (structure_mapper self rest)
385+
345386let unsafe_mapper : mapper =
346387 { default_mapper with
347388 expr = expr_mapper;
348389 typ = typ_mapper ;
349390 class_type = class_type_mapper;
350391 signature_item = signature_item_mapper ;
351392 value_bindings = Ast_tuple_pattern_flatten. value_bindings_mapper;
352- structure_item = structure_item_mapper
393+ structure_item = structure_item_mapper;
394+ structure = structure_mapper
353395 }
354396
355397
0 commit comments