diff --git a/src/reason-parser/reason_parser.mly b/src/reason-parser/reason_parser.mly index a3b8778c6..e9d04d25f 100644 --- a/src/reason-parser/reason_parser.mly +++ b/src/reason-parser/reason_parser.mly @@ -1966,8 +1966,12 @@ signature_item: | item_attributes opt_LET_MODULE_REC_ident module_type_body(COLON) and_module_rec_declaration* { let loc = mklocation $symbolstartpos $endpos($3) in - let _ext, letmodule = $2 in - Psig_recmodule (Ast_helper.Md.mk letmodule $3 ~attrs:$1 ~loc :: $4) } + let ext, letmodule = $2 in + wrap_sig_ext + ~loc + (Psig_recmodule (Ast_helper.Md.mk letmodule $3 ~attrs:$1 ~loc :: $4)) + ext + } | item_attributes MODULE TYPE as_loc(ident) { let loc = mklocation $symbolstartpos $endpos in Psig_modtype (Ast_helper.Mtd.mk $4 ~attrs:$1 ~loc) diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 58059266c..31144c30b 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -7212,6 +7212,7 @@ let printer = object(self:'self) | Psig_value ({ pval_prim = [_]; _ } as vd) -> self#primitive_declaration ~extension vd | Psig_value vd -> self#val_binding ~extension vd | Psig_module pmd -> self#psig_module ~extension pmd + | Psig_recmodule pmd -> self#psig_recmodule ~extension pmd | _ -> self#payload "%%" extension (PSig [item]) end | _ -> self#signature_item' item @@ -7263,6 +7264,45 @@ let printer = object(self:'self) ~layout:(self#attach_std_item_attrs stdAttrs @@ layout) () + method psig_recmodule ?extension decls = + let items = List.mapi (fun i xx -> + let {stdAttrs; docAttrs} = + partitionAttributes ~partDoc:true xx.pmd_attributes + in + let letPattern = + makeList [ + makeList ~postSpace:true [ + atom (if i == 0 + then + add_extension_sugar "module" extension ^ " rec" + else "and"); + atom (moduleIdent xx.pmd_name) + ]; + atom ":" + ] + in + let layout = + self#attach_std_item_attrs stdAttrs + (self#module_type ~space:true letPattern xx.pmd_type) + in + let layoutWithDocAttrs = + self#attachDocAttrsToLayout + ~stdAttrs + ~docAttrs + ~loc:xx.pmd_name.loc + ~layout + () + in + (extractLocModDecl xx, layoutWithDocAttrs) + ) decls + in + makeNonIndentedBreakingList + (groupAndPrint + ~xf:(fun (_, layout) -> layout) + ~getLoc:(fun (loc, _) -> loc) + ~comments:self#comments + items) + method signature_item' x : Layout.t = let item: Layout.t = match x.psig_desc with @@ -7361,42 +7401,7 @@ let printer = object(self:'self) ~layout () | Psig_class_type l -> self#class_type_declaration_list l - | Psig_recmodule decls -> - let items = List.mapi (fun i xx -> - let {stdAttrs; docAttrs} = - partitionAttributes ~partDoc:true xx.pmd_attributes - in - let letPattern = - makeList [ - makeList ~postSpace:true [ - atom (if i == 0 then "module rec" else "and"); - atom (moduleIdent xx.pmd_name) - ]; - atom ":" - ] - in - let layout = - self#attach_std_item_attrs stdAttrs - (self#module_type ~space:true letPattern xx.pmd_type) - in - let layoutWithDocAttrs = - self#attachDocAttrsToLayout - ~stdAttrs - ~docAttrs - ~loc:xx.pmd_name.loc - ~layout - () - in - (extractLocModDecl xx, layoutWithDocAttrs) - ) decls - in - makeNonIndentedBreakingList - (groupAndPrint - ~xf:(fun (_, layout) -> layout) - ~getLoc:(fun (loc, _) -> loc) - ~comments:self#comments - items) - + | Psig_recmodule decls -> self#psig_recmodule decls | Psig_attribute a -> self#floating_attribute a | Psig_extension (({loc}, _) as ext, attrs) -> let {stdAttrs; docAttrs} = @@ -7829,8 +7834,7 @@ let printer = object(self:'self) self#moduleExpressionToFormattedApplicationItems ~prefix:"include" moduleExpr - | Pstr_recmodule decls -> (* 3.07 *) - self#recmodule decls + | Pstr_recmodule decls -> self#recmodule decls | Pstr_attribute a -> self#floating_attribute a | Pstr_extension ((_extension, PStr []) as extension, attrs) -> (* Extension with attributes and without PStr gets printed inline *) diff --git a/test/general-syntax-rei.t/input.rei b/test/general-syntax-rei.t/input.rei index baff64c25..2b535b6f4 100644 --- a/test/general-syntax-rei.t/input.rei +++ b/test/general-syntax-rei.t/input.rei @@ -50,3 +50,5 @@ module%foo X: Y; module%foo X = Y; +module%foo rec X: Y; + diff --git a/test/general-syntax-rei.t/run.t b/test/general-syntax-rei.t/run.t index 24c83d683..65b1aae1f 100644 --- a/test/general-syntax-rei.t/run.t +++ b/test/general-syntax-rei.t/run.t @@ -58,3 +58,5 @@ Format general interface syntax module%foo X: Y; module%foo X = Y; + + module%foo rec X: Y;