123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453openResultopenOdoc_model.PathsopenOdoc_model.NamesmoduleRoot=Odoc_model.Rootletrender_path:Odoc_model.Paths.Path.t->string=letopenOdoc_model.Paths.Pathinletrecrender_resolved:Odoc_model.Paths.Path.Resolved.t->string=letopenResolvedinfunction|`Identifierid->Identifier.nameid|`OpaqueModulep->render_resolved(p:>t)|`OpaqueModuleTypep->render_resolved(p:>t)|`Subst(_,p)->render_resolved(p:>t)|`SubstT(_,p)->render_resolved(p:>t)|`Alias(dest,`Resolvedsrc)->ifOdoc_model.Paths.Path.Resolved.(is_hidden(src:>t))thenrender_resolved(dest:>t)elserender_resolved(src:>t)|`Alias(dest,src)->ifOdoc_model.Paths.Path.is_hidden(src:>Path.t)thenrender_resolved(dest:>t)elserender_path(src:>Path.t)|`AliasModuleType(p1,p2)->ifOdoc_model.Paths.Path.Resolved.(is_hidden(p2:>t))thenrender_resolved(p1:>t)elserender_resolved(p2:>t)|`Hiddenp->render_resolved(p:>t)|`Module(p,s)->render_resolved(p:>t)^"."^ModuleName.to_strings|`Canonical(_,`Resolvedp)->render_resolved(p:>t)|`Canonical(p,_)->render_resolved(p:>t)|`CanonicalModuleType(_,`Resolvedp)->render_resolved(p:>t)|`CanonicalModuleType(p,_)->render_resolved(p:>t)|`CanonicalType(_,`Resolvedp)->render_resolved(p:>t)|`CanonicalType(p,_)->render_resolved(p:>t)|`CanonicalDataType(_,`Resolvedp)->render_resolved(p:>t)|`CanonicalDataType(p,_)->render_resolved(p:>t)|`Apply(rp,p)->render_resolved(rp:>t)^"("^render_resolved(p:>Odoc_model.Paths.Path.Resolved.t)^")"|`ModuleType(p,s)->render_resolved(p:>t)^"."^ModuleTypeName.to_strings|`Type(p,s)->render_resolved(p:>t)^"."^TypeName.to_strings|`Value(p,s)->render_resolved(p:>t)^"."^ValueName.to_strings|`Constructor(p,s)->render_resolved(p:>t)^"."^ConstructorName.to_strings|`Class(p,s)->render_resolved(p:>t)^"."^ClassName.to_strings|`ClassType(p,s)->render_resolved(p:>t)^"."^ClassTypeName.to_stringsandrender_path:Odoc_model.Paths.Path.t->string=funx->matchxwith|`Identifier(id,_)->Identifier.nameid|`Rootroot->root|`Forwardroot->root|`Dot(prefix,suffix)->render_path(prefix:>t)^"."^suffix|`Apply(p1,p2)->render_path(p1:>t)^"("^render_path(p2:>t)^")"|`Resolvedrp->render_resolvedrpinrender_pathmoduleError=structtypenonrect=|Not_linkableofstring|Uncaught_exnofstring(* These should basicaly never happen *)|Unexpected_anchorofstringletto_string=function|Not_linkables->Printf.sprintf"Not_linkable %S"s|Uncaught_exns->Printf.sprintf"Uncaught_exn %S"s|Unexpected_anchors->Printf.sprintf"Unexpected_anchor %S"sendlet(>>=)xf=matchxwithOkx->fx|Error_ase->emodulePath=structtypenonsrc_pv=[Identifier.Page.t_pv|Identifier.Signature.t_pv|Identifier.ClassSignature.t_pv]typeany_pv=[nonsrc_pv|Identifier.SourcePage.t_pv|Identifier.SourceDir.t_pv|Identifier.AssetFile.t_pv]andany=any_pvOdoc_model.Paths.Identifier.idtypekind=[`Module|`Page|`LeafPage|`ModuleType|`Parameterofint|`Class|`ClassType|`File|`SourcePage]letstring_of_kind:kind->string=function|`Page->"page"|`Module->"module"|`LeafPage->"leaf-page"|`ModuleType->"module-type"|`Parameterarg_num->Printf.sprintf"argument-%d"arg_num|`Class->"class"|`ClassType->"class-type"|`File->"file"|`SourcePage->"source"letpp_kindfmtkind=Format.fprintffmt"%s"(string_of_kindkind)typet={kind:kind;parent:toption;name:string}letmk?parentkindname={kind;parent;name}letrecfrom_identifier:any->t=funx->matchxwith|{iv=`Root(parent,unit_name);_}->letparent=matchparentwith|Somep->Some(from_identifier(p:>any))|None->Noneinletkind=`Moduleinletname=ModuleName.to_stringunit_nameinmk?parentkindname|{iv=`Page(parent,page_name);_}->letparent=matchparentwith|Somep->Some(from_identifier(p:>any))|None->Noneinletkind=`Pageinletname=PageName.to_stringpage_nameinmk?parentkindname|{iv=`LeafPage(parent,page_name);_}->letparent=matchparentwith|Somep->Some(from_identifier(p:>any))|None->Noneinletkind=`LeafPageinletname=PageName.to_stringpage_nameinmk?parentkindname|{iv=`Module(parent,mod_name);_}->letparent=from_identifier(parent:>any)inletkind=`Moduleinletname=ModuleName.to_stringmod_nameinmk~parentkindname|{iv=`Parameter(functor_id,arg_name);_}asp->letparent=from_identifier(functor_id:>any)inletarg_num=Identifier.FunctorParameter.functor_arg_pospinletkind=`Parameterarg_numinletname=ModuleName.to_stringarg_nameinmk~parentkindname|{iv=`ModuleType(parent,modt_name);_}->letparent=from_identifier(parent:>any)inletkind=`ModuleTypeinletname=ModuleTypeName.to_stringmodt_nameinmk~parentkindname|{iv=`Class(parent,name);_}->letparent=from_identifier(parent:>any)inletkind=`Classinletname=ClassName.to_stringnameinmk~parentkindname|{iv=`ClassType(parent,name);_}->letparent=from_identifier(parent:>any)inletkind=`ClassTypeinletname=ClassTypeName.to_stringnameinmk~parentkindname|{iv=`Resultp;_}->from_identifier(p:>any)|{iv=`SourceDir(parent,name);_}->letparent=from_identifier(parent:>any)inletkind=`Pageinmk~parentkindname|{iv=`SourcePage(parent,name);_}->letparent=from_identifier(parent:>any)inletkind=`SourcePageinmk~parentkindname|{iv=`AssetFile(parent,name);_}->letparent=from_identifier(parent:>any)inletkind=`Fileinmk~parentkindnameletfrom_identifierp=from_identifier(p:[<any_pv]Odoc_model.Paths.Identifier.id:>any)letto_listurl=letrecloopacc{parent;name;kind}=matchparentwith|None->(kind,name)::acc|Somep->loop((kind,name)::acc)pinloop[]urlletof_listl=letrecinnerparent=function|[]->parent|(kind,name)::xs->inner(Some{parent;name;kind})xsininnerNonelletsplit:is_dir:(kind->[`Always|`Never|`IfNotLast])->(kind*string)list->(kind*string)list*(kind*string)list=fun~is_dirl->letrecinnerdirs=function|[((kind,_)asx)]whenis_dirkind=`IfNotLast->(List.revdirs,[x])|((kind,_)asx)::xswhenis_dirkind<>`Never->inner(x::dirs)xs|xs->(List.revdirs,xs)ininner[]lendmoduleAnchor=structtypekind=[Path.kind|`Section|`Type|`Extension|`ExtensionDecl|`Exception|`Method|`Val|`Constructor|`Field|`SourceAnchor]letstring_of_kind:kind->string=function|#Path.kindask->Path.string_of_kindk|`Section->"section"|`Type->"type"|`Extension->"extension"|`ExtensionDecl->"extension-decl"|`Exception->"exception"|`Method->"method"|`Val->"val"|`Constructor->"constructor"|`Field->"field"|`SourceAnchor->"source-anchor"letpp_kindfmtkind=Format.fprintffmt"%s"(string_of_kindkind)typet={page:Path.t;anchor:string;kind:kind}letanchorify_path{Path.parent;name;kind}=matchparentwith|None->assertfalse(* We got a root, should never happen *)|Somepage->letanchor=Printf.sprintf"%s-%s"(Path.string_of_kindkind)namein{page;anchor;kind=(kind:>kind)}letadd_suffix~kind{page;anchor;_}suffix={page;anchor=anchor^"."^suffix;kind}letmk~kindparentstr_name=letpage=Path.from_identifierparentinOk{page;anchor=str_name;kind}letrecfrom_identifier:Identifier.t->(t,Error.t)result=letopenErrorinfunction|{iv=`Module(parent,mod_name);_}->letparent=Path.from_identifier(parent:>Path.any)inletkind=`Moduleinletanchor=Printf.sprintf"%s-%s"(Path.string_of_kindkind)(ModuleName.to_stringmod_name)inOk{page=parent;anchor;kind}|{iv=`Root_;_}asp->letpage=Path.from_identifier(p:>Path.any)inOk{page;kind=`Module;anchor=""}|{iv=`Page_;_}asp->letpage=Path.from_identifier(p:>Path.any)inOk{page;kind=`Page;anchor=""}|{iv=`LeafPage_;_}asp->letpage=Path.from_identifier(p:>Path.any)inOk{page;kind=`LeafPage;anchor=""}(* For all these identifiers, page names and anchors are the same *)|{iv=`Parameter_|`Result_|`ModuleType_|`Class_|`ClassType_;_;}asp->Ok(anchorify_path@@Path.from_identifierp)|{iv=`Type(parent,type_name);_}->letpage=Path.from_identifier(parent:>Path.any)inletkind=`TypeinOk{page;anchor=Format.asprintf"%a-%s"pp_kindkind(TypeName.to_stringtype_name);kind;}|{iv=`CoreTypety_name;_}->Error(Not_linkable("core_type:"^TypeName.to_stringty_name))|{iv=`Extension(parent,name);_}->letpage=Path.from_identifier(parent:>Path.any)inletkind=`ExtensioninOk{page;anchor=Format.asprintf"%a-%s"pp_kindkind(ExtensionName.to_stringname);kind;}|{iv=`ExtensionDecl(parent,name,_);_}->letpage=Path.from_identifier(parent:>Path.any)inletkind=`ExtensionDeclinOk{page;anchor=Format.asprintf"%a-%s"pp_kindkind(ExtensionName.to_stringname);kind;}|{iv=`Exception(parent,name);_}->letpage=Path.from_identifier(parent:>Path.any)inletkind=`ExceptioninOk{page;anchor=Format.asprintf"%a-%s"pp_kindkind(ExceptionName.to_stringname);kind;}|{iv=`CoreExceptionname;_}->Error(Not_linkable("core_exception:"^ExceptionName.to_stringname))|{iv=`Value(parent,name);_}->letpage=Path.from_identifier(parent:>Path.any)inletkind=`ValinOk{page;anchor=Format.asprintf"%a-%s"pp_kindkind(ValueName.to_stringname);kind;}|{iv=`Method(parent,name);_}->letstr_name=MethodName.to_stringnameinletpage=Path.from_identifier(parent:>Path.any)inletkind=`MethodinOk{page;anchor=Format.asprintf"%a-%s"pp_kindkindstr_name;kind}|{iv=`InstanceVariable(parent,name);_}->letstr_name=InstanceVariableName.to_stringnameinletpage=Path.from_identifier(parent:>Path.any)inletkind=`ValinOk{page;anchor=Format.asprintf"%a-%s"pp_kindkindstr_name;kind}|{iv=`Constructor(parent,name);_}->from_identifier(parent:>Identifier.t)>>=funpage->letkind=`Constructorinletsuffix=ConstructorName.to_stringnameinOk(add_suffix~kindpagesuffix)|{iv=`Field(parent,name);_}->from_identifier(parent:>Identifier.t)>>=funpage->letkind=`Fieldinletsuffix=FieldName.to_stringnameinOk(add_suffix~kindpagesuffix)|{iv=`Label(parent,anchor);_}->(letstr_name=LabelName.to_stringanchorin(* [Identifier.LabelParent.t] contains datatypes. [`CoreType] can't
happen, [`Type] may not happen either but just in case, use the
grand-parent. *)matchparentwith|{iv=`CoreType_;_}->Error(Unexpected_anchor"core_type label parent")|{iv=`Type(gp,_);_}->mk~kind:`Sectiongpstr_name|{iv=#Path.nonsrc_pv;_}asp->mk~kind:`Section(p:>Path.any)str_name)|{iv=`SourceLocation(parent,loc);_}->letpage=Path.from_identifier(parent:>Path.any)inOk{page;kind=`SourceAnchor;anchor=DefName.to_stringloc}|{iv=`SourceLocationInternal(parent,loc);_}->letpage=Path.from_identifier(parent:>Path.any)inOk{page;kind=`SourceAnchor;anchor=LocalName.to_stringloc}|{iv=`SourceLocationModparent;_}->letpage=Path.from_identifier(parent:>Path.any)inOk{page;kind=`SourceAnchor;anchor=""}|{iv=`SourcePage_|`SourceDir_;_}asp->letpage=Path.from_identifier(p:>Path.any)inOk{page;kind=`Page;anchor=""}|{iv=`AssetFile_;_}asp->letpage=Path.from_identifierpinOk{page;kind=`File;anchor=""}letpolymorphic_variant~type_identelt=letname_of_type_constrte=matchtewith|Odoc_model.Lang.TypeExpr.Constr(path,_)->render_path(path:>Odoc_model.Paths.Path.t)|_->invalid_arg"DocOckHtml.Url.Polymorphic_variant_decl.name_of_type_constr"inmatchfrom_identifiertype_identwith|Errore->failwith(Error.to_stringe)|Okurl->(matcheltwith|Odoc_model.Lang.TypeExpr.Polymorphic_variant.Typete->letkind=`Typeinletsuffix=name_of_type_constrteinadd_suffix~kindurlsuffix|Constructor{name;_}->letkind=`Constructorinletsuffix=nameinadd_suffix~kindurlsuffix)(** The anchor looks like
[extension-decl-"Path.target_type"-FirstConstructor]. *)letextension_decl(decl:Odoc_model.Lang.Extension.t)=letpage=Path.from_identifier(decl.parent:>Path.any)inletkind=`ExtensionDeclinletfirst_cons=Identifier.name(List.hddecl.constructors).idinletanchor=Format.asprintf"%a-%s"pp_kindkindfirst_consin{page;kind;anchor}letsource_anchorpathanchor={page=path;anchor;kind=`SourceAnchor}endtypekind=Anchor.kindtypet=Anchor.tletfrom_pathpage={Anchor.page;anchor="";kind=(page.kind:>Anchor.kind)}letfrom_identifier~stop_before=function|{Odoc_model.Paths.Identifier.iv=#Path.any_pv;_}aspwhennotstop_before->Ok(from_path@@Path.from_identifierp)|p->Anchor.from_identifierpletkindid=matchAnchor.from_identifieridwith|Errore->failwith(Error.to_stringe)|Ok{kind;_}->kind