this repo has no description

tuples, objects and module types

Signed-off-by: Paul-Elliot <peada@free.fr>

authored by

Paul-Elliot and committed by jon.recoil.org 8c24f90d ddfab0a5

+59 -48
+3 -3
src/document/ML.ml
··· 4 5 module ML = Generator.Make (struct 6 module Obj = struct 7 - let close_tag_closed = ">" 8 9 let close_tag_extendable = ".. >" 10 ··· 22 23 let handle_constructor_params = handle_params 24 25 - let handle_substitution_params = handle_params 26 27 let handle_format_params p = p 28 ··· 37 end 38 39 module Tuple = struct 40 - let element_separator = " * " 41 42 let always_parenthesize = false 43 end
··· 4 5 module ML = Generator.Make (struct 6 module Obj = struct 7 + let close_tag_closed = " >" 8 9 let close_tag_extendable = ".. >" 10 ··· 22 23 let handle_constructor_params = handle_params 24 25 + let handle_substitution_params name args = O.span (args ++ O.txt " " ++ name) 26 27 let handle_format_params p = p 28 ··· 37 end 38 39 module Tuple = struct 40 + let element_separator = O.sp ++ O.txt "* " 41 42 let always_parenthesize = false 43 end
+2 -2
src/document/codefmt.ml
··· 134 () 135 136 let elt ppf (elt : Inline.t) = 137 - Format.fprintf ppf "@{<tag:%s>%s@}" (Marshal.to_string elt []) 138 - (String.make (Utils.compute_length_inline elt) ' ') 139 140 let ignore ppf txt = Format.fprintf ppf "@{<ignore-tag>%t@}" txt 141 end
··· 134 () 135 136 let elt ppf (elt : Inline.t) = 137 + Format.fprintf ppf "@{<tag:%s>%t@}" (Marshal.to_string elt []) (fun fmt -> 138 + Format.pp_print_as fmt (Utils.compute_length_inline elt) "") 139 140 let ignore ppf txt = Format.fprintf ppf "@{<ignore-tag>%t@}" txt 141 end
+52 -41
src/document/generator.ml
··· 271 272 and te_object (t : Odoc_model.Lang.TypeExpr.Object.t) = 273 let fields = 274 - O.list t.fields ~f:(function 275 - | Odoc_model.Lang.TypeExpr.Object.Method { name; type_ } -> 276 - O.txt (name ^ Syntax.Type.annotation_separator) 277 - ++ type_expr type_ 278 - ++ O.txt Syntax.Obj.field_separator 279 - | Inherit type_ -> type_expr type_ ++ O.txt Syntax.Obj.field_separator) 280 in 281 let open_tag = 282 if t.open_ then O.txt Syntax.Obj.open_tag_extendable ··· 341 if not needs_parentheses then res else enclose ~l:"( " res ~r:" )" 342 | Tuple lst -> 343 let res = 344 - O.list lst 345 - ~sep:(O.txt Syntax.Type.Tuple.element_separator) 346 ~f:(type_expr ~needs_parentheses:true) 347 in 348 if Syntax.Type.Tuple.always_parenthesize || needs_parentheses then ··· 470 | Tuple [] -> O.documentedSrc (cstr ++ ret_type) 471 | Tuple lst -> 472 let params = 473 - O.list lst 474 - ~sep:(O.txt Syntax.Type.Tuple.element_separator) 475 ~f:(type_expr ~needs_parentheses:is_gadt) 476 in 477 O.documentedSrc ··· 1204 1205 and module_type_substitution (t : Odoc_model.Lang.ModuleTypeSubstitution.t) 1206 = 1207 let modname = Paths.Identifier.name t.id in 1208 let modname, expansion_doc, mty = 1209 module_type_manifest ~subst:true modname t.id t.doc (Some t.manifest) 1210 in 1211 let content = 1212 - O.documentedSrc 1213 - (O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " ") 1214 - @ modname @ mty 1215 @ O.documentedSrc 1216 (if Syntax.Mod.close_tag_semicolon then O.txt ";" else O.noop) 1217 in ··· 1361 | Alias (mod_path, _) -> Link.from_path (mod_path :> Paths.Path.t) 1362 | ModuleType mt -> mty mt 1363 1364 - and module_type_manifest ~subst modname id doc manifest = 1365 let expansion = 1366 match manifest with 1367 | None -> None ··· 1369 in 1370 let modname, expansion, expansion_doc = 1371 match expansion with 1372 - | None -> (O.documentedSrc @@ O.txt modname, None, None) 1373 | Some (expansion_doc, items) -> 1374 let url = Url.Path.from_identifier id in 1375 let link = path url [ inline @@ Text modname ] in 1376 let page = 1377 make_expansion_page modname `Mty url [ doc; expansion_doc ] items 1378 in 1379 - (O.documentedSrc link, Some page, Some expansion_doc) 1380 in 1381 let summary = 1382 match manifest with 1383 | None -> O.noop 1384 - | Some expr -> (if subst then O.txt " := " else O.txt " = ") ++ mty expr 1385 in 1386 ( modname, 1387 expansion_doc, 1388 attach_expansion (" = ", "sig", "end") expansion summary ) 1389 1390 and module_type (t : Odoc_model.Lang.ModuleType.t) = 1391 let modname = Paths.Identifier.name t.id in 1392 let modname, expansion_doc, mty = 1393 - module_type_manifest ~subst:false modname t.id t.doc t.expr 1394 in 1395 let content = 1396 - O.documentedSrc 1397 - (O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " ") 1398 - @ modname @ mty 1399 @ O.documentedSrc 1400 (if Syntax.Mod.close_tag_semicolon then O.txt ";" else O.noop) 1401 in ··· 1421 | _ -> false 1422 1423 and mty_with subs expr = 1424 - umty expr ++ O.txt " " ++ O.keyword "with" ++ O.txt " " 1425 ++ O.list 1426 - ~sep:(O.txt " " ++ O.keyword "and" ++ O.txt " ") 1427 ~f:(fun x -> O.span (substitution x)) 1428 subs 1429 ··· 1469 | Functor (Unit, expr) -> 1470 (if Syntax.Mod.functor_keyword then O.keyword "functor" else O.noop) 1471 ++ O.span (O.txt " () " ++ Syntax.Type.arrow) 1472 - ++ O.txt " " ++ mty expr 1473 | Functor (Named arg, expr) -> 1474 let arg_expr = arg.expr in 1475 let stop_before = expansion_of_module_type_expr arg_expr = None in ··· 1483 | Ok href -> resolved href [ inline @@ Text name ] 1484 in 1485 (if Syntax.Mod.functor_keyword then O.keyword "functor" else O.noop) 1486 - ++ O.span 1487 - (O.txt " (" ++ name 1488 - ++ O.txt Syntax.Type.annotation_separator 1489 - ++ mty arg_expr ++ O.txt ")" ++ O.txt " " ++ Syntax.Type.arrow 1490 - ) 1491 - ++ O.txt " " ++ mty expr 1492 | With { w_expr; _ } when is_elidable_with_u w_expr -> 1493 Syntax.Mod.open_tag ++ O.txt " ... " ++ Syntax.Mod.close_tag 1494 - | With { w_substitutions; w_expr; _ } -> mty_with w_substitutions w_expr 1495 | TypeOf { t_desc; _ } -> mty_typeof t_desc 1496 | Signature _ -> 1497 Syntax.Mod.open_tag ++ O.txt " ... " ++ Syntax.Mod.close_tag ··· 1523 | Error _ -> O.txt name 1524 | Ok href -> resolved href [ inline @@ Text name ] 1525 in 1526 - O.txt "(" ++ name 1527 - ++ O.txt Syntax.Type.annotation_separator 1528 - ++ mty arg.expr ++ O.txt ")" 1529 in 1530 O.sp ++ text_arg ++ mty_in_decl base expr 1531 ··· 1539 and substitution : Odoc_model.Lang.ModuleType.substitution -> text = 1540 function 1541 | ModuleEq (frag_mod, md) -> 1542 - O.keyword "module" ++ O.sp 1543 ++ Link.from_fragment (frag_mod :> Paths.Fragment.leaf) 1544 - ++ O.sp ++ O.txt "= " ++ mdexpr md 1545 | ModuleTypeEq (frag_mty, md) -> 1546 O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " " 1547 ++ Link.from_fragment (frag_mty :> Paths.Fragment.leaf) 1548 ++ O.txt " = " ++ mty md 1549 | TypeEq (frag_typ, td) -> 1550 - O.keyword "type" ++ O.sp 1551 ++ type_expr_in_subst td (frag_typ :> Paths.Fragment.leaf) 1552 ++ fst (format_manifest td) 1553 ++ format_constraints td.Odoc_model.Lang.TypeDecl.Equation.constraints 1554 | ModuleSubst (frag_mod, mod_path) -> 1555 - O.keyword "module" ++ O.sp 1556 ++ Link.from_fragment (frag_mod :> Paths.Fragment.leaf) 1557 - ++ O.sp ++ O.txt ":= " 1558 ++ Link.from_path (mod_path :> Paths.Path.t) 1559 | ModuleTypeSubst (frag_mty, md) -> 1560 O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " " 1561 ++ Link.from_fragment (frag_mty :> Paths.Fragment.leaf) 1562 ++ O.txt " := " ++ mty md 1563 | TypeSubst (frag_typ, td) -> ( 1564 - O.keyword "type" ++ O.sp 1565 ++ type_expr_in_subst td (frag_typ :> Paths.Fragment.leaf) 1566 - ++ O.sp ++ O.txt ":= " 1567 ++ 1568 match td.Lang.TypeDecl.Equation.manifest with 1569 | None -> assert false (* cf loader/cmti *)
··· 271 272 and te_object (t : Odoc_model.Lang.TypeExpr.Object.t) = 273 let fields = 274 + O.list 275 + ~sep:(O.sp ++ O.txt Syntax.Obj.field_separator) 276 + t.fields 277 + ~f:(function 278 + | Odoc_model.Lang.TypeExpr.Object.Method { name; type_ } -> 279 + O.box_hv_no_indent 280 + @@ O.txt (name ^ Syntax.Type.annotation_separator) 281 + ++ O.cut ++ type_expr type_ 282 + | Inherit type_ -> O.box_hv_no_indent @@ type_expr type_) 283 in 284 let open_tag = 285 if t.open_ then O.txt Syntax.Obj.open_tag_extendable ··· 344 if not needs_parentheses then res else enclose ~l:"( " res ~r:" )" 345 | Tuple lst -> 346 let res = 347 + O.list lst ~sep:Syntax.Type.Tuple.element_separator 348 ~f:(type_expr ~needs_parentheses:true) 349 in 350 if Syntax.Type.Tuple.always_parenthesize || needs_parentheses then ··· 472 | Tuple [] -> O.documentedSrc (cstr ++ ret_type) 473 | Tuple lst -> 474 let params = 475 + O.list lst ~sep:Syntax.Type.Tuple.element_separator 476 ~f:(type_expr ~needs_parentheses:is_gadt) 477 in 478 O.documentedSrc ··· 1205 1206 and module_type_substitution (t : Odoc_model.Lang.ModuleTypeSubstitution.t) 1207 = 1208 + let prefix = 1209 + O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " " 1210 + in 1211 let modname = Paths.Identifier.name t.id in 1212 let modname, expansion_doc, mty = 1213 module_type_manifest ~subst:true modname t.id t.doc (Some t.manifest) 1214 + prefix 1215 in 1216 let content = 1217 + O.documentedSrc (prefix ++ modname) 1218 + @ mty 1219 @ O.documentedSrc 1220 (if Syntax.Mod.close_tag_semicolon then O.txt ";" else O.noop) 1221 in ··· 1365 | Alias (mod_path, _) -> Link.from_path (mod_path :> Paths.Path.t) 1366 | ModuleType mt -> mty mt 1367 1368 + and module_type_manifest ~subst modname id doc manifest prefix = 1369 let expansion = 1370 match manifest with 1371 | None -> None ··· 1373 in 1374 let modname, expansion, expansion_doc = 1375 match expansion with 1376 + | None -> (O.txt modname, None, None) 1377 | Some (expansion_doc, items) -> 1378 let url = Url.Path.from_identifier id in 1379 let link = path url [ inline @@ Text modname ] in 1380 let page = 1381 make_expansion_page modname `Mty url [ doc; expansion_doc ] items 1382 in 1383 + (link, Some page, Some expansion_doc) 1384 in 1385 let summary = 1386 match manifest with 1387 | None -> O.noop 1388 + | Some expr -> 1389 + O.ignore (prefix ++ modname) 1390 + ++ (if subst then O.txt " :=" ++ O.sp else O.txt " =" ++ O.sp) 1391 + ++ mty expr 1392 in 1393 ( modname, 1394 expansion_doc, 1395 attach_expansion (" = ", "sig", "end") expansion summary ) 1396 1397 and module_type (t : Odoc_model.Lang.ModuleType.t) = 1398 + let prefix = 1399 + O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " " 1400 + in 1401 let modname = Paths.Identifier.name t.id in 1402 let modname, expansion_doc, mty = 1403 + module_type_manifest ~subst:false modname t.id t.doc t.expr prefix 1404 in 1405 let content = 1406 + O.documentedSrc (prefix ++ modname) 1407 + @ mty 1408 @ O.documentedSrc 1409 (if Syntax.Mod.close_tag_semicolon then O.txt ";" else O.noop) 1410 in ··· 1430 | _ -> false 1431 1432 and mty_with subs expr = 1433 + umty expr ++ O.sp ++ O.keyword "with" ++ O.txt " " 1434 ++ O.list 1435 + ~sep:(O.cut ++ O.txt " " ++ O.keyword "and" ++ O.txt " ") 1436 ~f:(fun x -> O.span (substitution x)) 1437 subs 1438 ··· 1478 | Functor (Unit, expr) -> 1479 (if Syntax.Mod.functor_keyword then O.keyword "functor" else O.noop) 1480 ++ O.span (O.txt " () " ++ Syntax.Type.arrow) 1481 + ++ O.sp ++ mty expr 1482 | Functor (Named arg, expr) -> 1483 let arg_expr = arg.expr in 1484 let stop_before = expansion_of_module_type_expr arg_expr = None in ··· 1492 | Ok href -> resolved href [ inline @@ Text name ] 1493 in 1494 (if Syntax.Mod.functor_keyword then O.keyword "functor" else O.noop) 1495 + ++ (O.box_hv @@ O.span 1496 + @@ O.txt " (" ++ name 1497 + ++ O.txt Syntax.Type.annotation_separator 1498 + ++ mty arg_expr ++ O.txt ")" ++ O.txt " " ++ Syntax.Type.arrow 1499 + ) 1500 + ++ O.sp ++ mty expr 1501 | With { w_expr; _ } when is_elidable_with_u w_expr -> 1502 Syntax.Mod.open_tag ++ O.txt " ... " ++ Syntax.Mod.close_tag 1503 + | With { w_substitutions; w_expr; _ } -> 1504 + O.box_hv @@ (O.txt "a" ++ mty_with w_substitutions w_expr) 1505 | TypeOf { t_desc; _ } -> mty_typeof t_desc 1506 | Signature _ -> 1507 Syntax.Mod.open_tag ++ O.txt " ... " ++ Syntax.Mod.close_tag ··· 1533 | Error _ -> O.txt name 1534 | Ok href -> resolved href [ inline @@ Text name ] 1535 in 1536 + O.box_hv 1537 + @@ O.txt "(" ++ name 1538 + ++ O.txt Syntax.Type.annotation_separator 1539 + ++ O.cut ++ mty arg.expr ++ O.txt ")" 1540 in 1541 O.sp ++ text_arg ++ mty_in_decl base expr 1542 ··· 1550 and substitution : Odoc_model.Lang.ModuleType.substitution -> text = 1551 function 1552 | ModuleEq (frag_mod, md) -> 1553 + O.keyword "module" ++ O.txt " " 1554 ++ Link.from_fragment (frag_mod :> Paths.Fragment.leaf) 1555 + ++ O.txt " " ++ O.txt "= " ++ mdexpr md 1556 | ModuleTypeEq (frag_mty, md) -> 1557 O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " " 1558 ++ Link.from_fragment (frag_mty :> Paths.Fragment.leaf) 1559 ++ O.txt " = " ++ mty md 1560 | TypeEq (frag_typ, td) -> 1561 + O.keyword "type" ++ O.txt " " 1562 ++ type_expr_in_subst td (frag_typ :> Paths.Fragment.leaf) 1563 ++ fst (format_manifest td) 1564 ++ format_constraints td.Odoc_model.Lang.TypeDecl.Equation.constraints 1565 | ModuleSubst (frag_mod, mod_path) -> 1566 + O.keyword "module" ++ O.txt " " 1567 ++ Link.from_fragment (frag_mod :> Paths.Fragment.leaf) 1568 + ++ O.txt " " ++ O.txt ":= " 1569 ++ Link.from_path (mod_path :> Paths.Path.t) 1570 | ModuleTypeSubst (frag_mty, md) -> 1571 O.keyword "module" ++ O.txt " " ++ O.keyword "type" ++ O.txt " " 1572 ++ Link.from_fragment (frag_mty :> Paths.Fragment.leaf) 1573 ++ O.txt " := " ++ mty md 1574 | TypeSubst (frag_typ, td) -> ( 1575 + O.keyword "type" ++ O.txt " " 1576 ++ type_expr_in_subst td (frag_typ :> Paths.Fragment.leaf) 1577 + ++ O.txt " " ++ O.txt ":= " 1578 ++ 1579 match td.Lang.TypeDecl.Equation.manifest with 1580 | None -> assert false (* cf loader/cmti *)
+1 -1
src/document/generator_signatures.ml
··· 40 end 41 42 module Tuple : sig 43 - val element_separator : string 44 45 val always_parenthesize : bool 46 end
··· 40 end 41 42 module Tuple : sig 43 + val element_separator : text 44 45 val always_parenthesize : bool 46 end
+1 -1
src/document/reason.ml
··· 35 end 36 37 module Tuple = struct 38 - let element_separator = ", " 39 40 let always_parenthesize = true 41 end
··· 35 end 36 37 module Tuple = struct 38 + let element_separator = O.txt ", " 39 40 let always_parenthesize = true 41 end