From 4b3fb5d6f29cc14434fa0a58c59cd38adc27ac1b Mon Sep 17 00:00:00 2001 From: octachron Date: Wed, 13 Jan 2021 10:24:40 +0100 Subject: module type S := ...: core --- parsing/ast_helper.ml | 1 + parsing/ast_helper.mli | 1 + parsing/ast_iterator.ml | 2 +- parsing/ast_mapper.ml | 2 ++ parsing/depend.ml | 2 +- parsing/parsetree.mli | 2 ++ parsing/pprintast.ml | 12 ++++++++---- parsing/printast.ml | 4 ++++ 8 files changed, 20 insertions(+), 6 deletions(-) (limited to 'parsing') diff --git a/parsing/ast_helper.ml b/parsing/ast_helper.ml index 2d51dda743..41f5fb9b8d 100644 --- a/parsing/ast_helper.ml +++ b/parsing/ast_helper.ml @@ -271,6 +271,7 @@ module Sig = struct let mod_subst ?loc a = mk ?loc (Psig_modsubst a) let rec_module ?loc a = mk ?loc (Psig_recmodule a) let modtype ?loc a = mk ?loc (Psig_modtype a) + let modtype_subst ?loc a = mk ?loc (Psig_modtypesubst a) let open_ ?loc a = mk ?loc (Psig_open a) let include_ ?loc a = mk ?loc (Psig_include a) let class_ ?loc a = mk ?loc (Psig_class a) diff --git a/parsing/ast_helper.mli b/parsing/ast_helper.mli index a498ece07d..42ce9e2e98 100644 --- a/parsing/ast_helper.mli +++ b/parsing/ast_helper.mli @@ -288,6 +288,7 @@ module Sig: val mod_subst: ?loc:loc -> module_substitution -> signature_item val rec_module: ?loc:loc -> module_declaration list -> signature_item val modtype: ?loc:loc -> module_type_declaration -> signature_item + val modtype_subst: ?loc:loc -> module_type_declaration -> signature_item val open_: ?loc:loc -> open_description -> signature_item val include_: ?loc:loc -> include_description -> signature_item val class_: ?loc:loc -> class_description list -> signature_item diff --git a/parsing/ast_iterator.ml b/parsing/ast_iterator.ml index 1cdb95310a..d1efda9782 100644 --- a/parsing/ast_iterator.ml +++ b/parsing/ast_iterator.ml @@ -285,7 +285,7 @@ module MT = struct | Psig_modsubst x -> sub.module_substitution sub x | Psig_recmodule l -> List.iter (sub.module_declaration sub) l - | Psig_modtype x -> sub.module_type_declaration sub x + | Psig_modtype x | Psig_modtypesubst x -> sub.module_type_declaration sub x | Psig_open x -> sub.open_description sub x | Psig_include x -> sub.include_description sub x | Psig_class l -> List.iter (sub.class_description sub) l diff --git a/parsing/ast_mapper.ml b/parsing/ast_mapper.ml index 720c16af34..7575f47b0b 100644 --- a/parsing/ast_mapper.ml +++ b/parsing/ast_mapper.ml @@ -318,6 +318,8 @@ module MT = struct | Psig_recmodule l -> rec_module ~loc (List.map (sub.module_declaration sub) l) | Psig_modtype x -> modtype ~loc (sub.module_type_declaration sub x) + | Psig_modtypesubst x -> + modtype_subst ~loc (sub.module_type_declaration sub x) | Psig_open x -> open_ ~loc (sub.open_description sub x) | Psig_include x -> include_ ~loc (sub.include_description sub x) | Psig_class l -> class_ ~loc (List.map (sub.class_description sub) l) diff --git a/parsing/depend.ml b/parsing/depend.ml index f1a155c1ba..d202ad3faf 100644 --- a/parsing/depend.ml +++ b/parsing/depend.ml @@ -382,7 +382,7 @@ and add_sig_item (bv, m) item = let bv' = add bv and m' = add m in List.iter (fun pmd -> add_modtype bv' pmd.pmd_type) decls; (bv', m') - | Psig_modtype x -> + | Psig_modtype x | Psig_modtypesubst x-> begin match x.pmtd_type with None -> () | Some mty -> add_modtype bv mty diff --git a/parsing/parsetree.mli b/parsing/parsetree.mli index 8337c289b3..8137de7470 100644 --- a/parsing/parsetree.mli +++ b/parsing/parsetree.mli @@ -769,6 +769,8 @@ and signature_item_desc = | Psig_modtype of module_type_declaration (* module type S = MT module type S *) + | Psig_modtypesubst of module_type_declaration + (* module type S := ... *) | Psig_open of open_description (* open X *) | Psig_include of include_description diff --git a/parsing/pprintast.ml b/parsing/pprintast.ml index 29351cc02a..d20ad646d4 100644 --- a/parsing/pprintast.ml +++ b/parsing/pprintast.ml @@ -1159,14 +1159,18 @@ and signature_item ctxt f x : unit = pp f "@[include@ %a@]%a" (module_type ctxt) incl.pincl_mod (item_attributes ctxt) incl.pincl_attributes - | Psig_modtype {pmtd_name=s; pmtd_type=md; pmtd_attributes=attrs} -> + | Psig_modtype {pmtd_name=s; pmtd_type=md; pmtd_attributes=attrs} + | Psig_modtypesubst {pmtd_name=s; pmtd_type=md; pmtd_attributes=attrs} as p -> pp f "@[module@ type@ %s%a@]%a" s.txt - (fun f md -> match md with - | None -> () - | Some mt -> + (fun f md -> match md, p with + | None, _ -> () + | Some mt, Psig_modtype _ -> pp_print_space f () ; pp f "@ =@ %a" (module_type ctxt) mt + | Some mt, _ -> + pp_print_space f () ; + pp f "@ :=@ %a" (module_type ctxt) mt ) md (item_attributes ctxt) attrs | Psig_class_type (l) -> class_type_declaration_list ctxt f l diff --git a/parsing/printast.ml b/parsing/printast.ml index c196256ecd..9469bf1720 100644 --- a/parsing/printast.ml +++ b/parsing/printast.ml @@ -730,6 +730,10 @@ and signature_item i ppf x = line i ppf "Psig_modtype %a\n" fmt_string_loc x.pmtd_name; attributes i ppf x.pmtd_attributes; modtype_declaration i ppf x.pmtd_type + | Psig_modtypesubst x -> + line i ppf "Psig_modtypesubst %a\n" fmt_string_loc x.pmtd_name; + attributes i ppf x.pmtd_attributes; + modtype_declaration i ppf x.pmtd_type | Psig_open od -> line i ppf "Psig_open %a %a\n" fmt_override_flag od.popen_override fmt_longident_loc od.popen_expr; -- cgit v1.2.1