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