123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238openOdoc_searchletjson_of_args(args:Odoc_model.Lang.TypeDecl.Constructor.argument)=matchargswith|Tupletel->`Object[("kind",`String"Tuple");("vals",`Array(List.map(funte->`String(Text.of_typete))tel));]|Recordfl->`Object[("kind",`String"Record");("fields",`Array(List.map(fun{Odoc_model.Lang.TypeDecl.Field.id;mutable_;type_;doc=_;}->`Object[("name",`String(Odoc_model.Paths.Identifier.nameid));("mutable",`Boolmutable_);("type",`String(Text.of_typetype_));])fl));]letrecof_idx=letopenOdoc_model.NamesinletopenOdoc_model.Paths.Identifierinletretkindname=`Object[("kind",`Stringkind);("name",`Stringname)]inmatchx.ivwith|`Root(_,name)->[ret"Root"(ModuleName.to_stringname)]|`Page(_,name)->[ret"Page"(PageName.to_stringname)]|`LeafPage(_,name)->[ret"Page"(PageName.to_stringname)]|`Module(parent,name)->ret"Module"(ModuleName.to_stringname)::of_id(parent:>t)|`Parameter(parent,name)->ret"Parameter"(ModuleName.to_stringname)::of_id(parent:>t)|`Resultx->of_id(x:>t)|`ModuleType(parent,name)->ret"ModuleType"(ModuleTypeName.to_stringname)::of_id(parent:>t)|`Type(parent,name)->ret"Type"(TypeName.to_stringname)::of_id(parent:>t)|`CoreTypename->[ret"CoreType"(TypeName.to_stringname)]|`Constructor(parent,name)->ret"Constructor"(ConstructorName.to_stringname)::of_id(parent:>t)|`Field(parent,name)->ret"Field"(FieldName.to_stringname)::of_id(parent:>t)|`Extension(parent,name)->ret"Extension"(ExtensionName.to_stringname)::of_id(parent:>t)|`ExtensionDecl(parent,_,name)->ret"ExtensionDecl"(ExtensionName.to_stringname)::of_id(parent:>t)|`Exception(parent,name)->ret"Exception"(ExceptionName.to_stringname)::of_id(parent:>t)|`CoreExceptionname->[ret"CoreException"(ExceptionName.to_stringname)]|`Value(parent,name)->ret"Value"(ValueName.to_stringname)::of_id(parent:>t)|`Class(parent,name)->ret"Class"(ClassName.to_stringname)::of_id(parent:>t)|`ClassType(parent,name)->ret"ClassType"(ClassTypeName.to_stringname)::of_id(parent:>t)|`Method(parent,name)->ret"Method"(MethodName.to_stringname)::of_id(parent:>t)|`InstanceVariable(parent,name)->ret"InstanceVariable"(InstanceVariableName.to_stringname)::of_id(parent:>t)|`Label(parent,name)->ret"Label"(LabelName.to_stringname)::of_id(parent:>t)|`SourceDir_|`SourceLocationMod_|`SourceLocation_|`SourcePage_|`SourceLocationInternal_|`AssetFile_->[`Null](* TODO *)letof_idn=`Array(List.rev@@of_id(n:>Odoc_model.Paths.Identifier.t))letof_doc(doc:Odoc_model.Comment.docs)=lettxt=Text.of_docdocin`Stringtxtletof_entry({Entry.id;doc;kind}asentry)html=letj_id=of_ididinletdoc=of_docdocinletkind=letreturnkindarr=`Object(("kind",`Stringkind)::arr)inmatchkindwith|TypeDecl{canonical=_;equation;representation=_}->let{Odoc_model.Lang.TypeDecl.Equation.params=_;private_;manifest;constraints;}=equationinletprivate_=`Boolprivate_inletmanifest=matchmanifestwith|None->`Null|Somete->`String(Text.of_typete)inletconstraints=`Array(List.map(fun(lhs,rhs)->`Object[("lhs",`String(Text.of_typelhs));("rhs",`String(Text.of_typerhs));])constraints)inreturn"TypeDecl"[("private",private_);("manifest",manifest);("constraints",constraints);]|Module->return"Module"[]|Value{value=_;type_}->return"Value"[("type",`String(Text.of_typetype_))]|DocParagraph->return"Doc"[("subkind",`String"Paragraph")]|DocHeading->return"Doc"[("subkind",`String"Heading")]|DocCodeBlock->return"Doc"[("subkind",`String"CodeBlock")]|DocMathBlock->return"Doc"[("subkind",`String"MathBlock")]|DocVerbatim->return"Doc"[("subkind",`String"Verbatim")]|Exception{args;res}->letargs=json_of_argsargsinletres=`String(Text.of_typeres)inreturn"Exception"[("args",args);("res",res)]|Class_type{virtual_;params=_}->return"ClassType"[("virtual",`Boolvirtual_)]|Method{private_;virtual_;type_}->return"Method"[("virtual",`Boolvirtual_);("private",`Boolprivate_);("type",`String(Text.of_typetype_));]|Class{virtual_;params=_}->return"Class"[("virtual",`Boolvirtual_)]|TypeExtension{type_path=_;type_params=_;private_}->(* TODO: include type_path and type_params *)return"TypeExtension"[("private",`Boolprivate_)]|ExtensionConstructor{args;res}->letargs=json_of_argsargsinletres=`String(Text.of_typeres)inreturn"ExtensionConstructor"[("args",args);("res",res)]|ModuleType->return"ModuleType"[]|Constructor{args;res}->letargs=json_of_argsargsinletres=`String(Text.of_typeres)inreturn"Constructor"[("args",args);("res",res)]|Field{mutable_;type_;parent_type}->return"Field"[("mutable",`Boolmutable_);("type",`String(Text.of_typetype_));("parent_type",`String(Text.of_typeparent_type));]inmatchJson_display.of_entryentryhtmlwith|Result.Okdisplay->Result.Ok(`Object[("id",j_id);("doc",doc);("kind",kind);("display",display)])|Error_ase->eletoutput_jsonppffirstentries=letoutput_jsonjson=letstr=Odoc_html.Json.to_stringjsoninFormat.fprintfppf"%s\n"strinList.fold_left(funfirst(entry,html)->letjson=of_entryentryhtmlinifnotfirstthenFormat.fprintfppf",";matchjsonwith|Okjson->output_jsonjson;false|Errore->Printf.eprintf"%S"(Odoc_document.Url.Error.to_stringe);true)firstentriesletunitppfu=letf(first,id)i=letentries=Entry.entries_of_itemidiinletentries=List.map(funentry->(entry,Html.of_entryentry))entriesinletid=matchiwith|CompilationUnitu->(u.id:>Odoc_model.Paths.Identifier.t)|TypeDecl_->id|Modulem->(m.id:>Odoc_model.Paths.Identifier.t)|Value_->id|Exception_->id|ClassTypect->(ct.id:>Odoc_model.Paths.Identifier.t)|Method_->id|Classc->(c.id:>Odoc_model.Paths.Identifier.t)|Extension_->id|ModuleTypemt->(mt.id:>Odoc_model.Paths.Identifier.t)|Doc_->idinletfirst=output_jsonppffirstentriesin(first,id)inlet_first=Odoc_model.Fold.unit~f(true,(u.Odoc_model.Lang.Compilation_unit.id:>Odoc_model.Paths.Identifier.t))uin()letpageppf(page:Odoc_model.Lang.Page.t)=letffirsti=letentries=Entry.entries_of_item(page.name:>Odoc_model.Paths.Identifier.t)iinletentries=List.map(funentry->(entry,Html.of_entryentry))entriesinoutput_jsonppffirstentriesinlet_first=Odoc_model.Fold.page~ftruepagein()