123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107openOr_error(*
* Copyright (c) 2014 Leo White <leo@lpw25.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)letresolve_and_substitute~env~output~warn_errorinput_fileread_file=Odoc_model.Error.set_warn_errorwarn_error;letfilename=Fs.File.to_stringinput_fileinmatchread_file~filename:filenamewith|Errore->Error(`Msg(Odoc_model.Error.to_stringe))|Okunit->letunit=Odoc_xref.Lookup.lookupunitinifnotunit.Odoc_model.Lang.Compilation_unit.interfacethen(Printf.eprintf"WARNING: not processing the \"interface\" file.%s\n%!"(ifnot(Filename.check_suffixfilename"cmt")then""(* ? *)elsePrintf.sprintf" Using %S while you should use the .cmti file"filename));letresolve_env=Env.buildenv(`Unitunit)inOdoc_xref.resolve(Env.resolverresolve_env)unit>>=funresolved->(* [expand unit] fetches [unit] from [env] to get the expansion of local, previously
defined, elements. We'd rather it got back the resolved bit so we rebuild an
environment with the resolved unit.
Note that this is bad and once rewritten expand should not fetch the unit it is
working on. *)letexpand_env=Env.buildenv(`Unitresolved)inOdoc_xref.expand(Env.expanderexpand_env)resolved>>=funexpanded->Compilation_unit.saveoutputexpanded;Ok()letroot_of_compilation_unit~package~hidden~module_name~digest=letfile_representation:Odoc_model.Root.Odoc_file.t=Odoc_model.Root.Odoc_file.create_unit~force_hidden:hiddenmodule_namein{Odoc_model.Root.package;file=file_representation;digest}letcmti~env~package~hidden~output~warn_errorinput=letmake_root=root_of_compilation_unit~package~hiddeninletread_file=Odoc_loader.read_cmti~make_rootinresolve_and_substitute~env~output~warn_errorinputread_fileletcmt~env~package~hidden~output~warn_errorinput=letmake_root=root_of_compilation_unit~package~hiddeninletread_file=Odoc_loader.read_cmt~make_rootinresolve_and_substitute~env~output~warn_errorinputread_fileletcmi~env~package~hidden~output~warn_errorinput=letmake_root=root_of_compilation_unit~package~hiddeninletread_file=Odoc_loader.read_cmi~make_rootinresolve_and_substitute~env~output~warn_errorinputread_file(* TODO: move most of this to doc-ock. *)letmld~env~package~output~warn_errorinput=Odoc_model.Error.set_warn_errorwarn_error;letroot_name=letpage_dash_root=Filename.chop_extension(Fs.File.(to_string@@basenameoutput))inString.subpage_dash_root(String.length"page-")(String.lengthpage_dash_root-String.length"page-")inletdigest=Digest.file(Fs.File.to_stringinput)inletroot=letfile=Odoc_model.Root.Odoc_file.create_pageroot_namein{Odoc_model.Root.package;file;digest}inletname=`Page(root,Odoc_model.Names.PageName.of_stringroot_name)inletlocation=letpos=Lexing.{pos_fname=Fs.File.to_stringinput;pos_lnum=0;pos_cnum=0;pos_bol=0}inLocation.{loc_start=pos;loc_end=pos;loc_ghost=true}inletresolvecontent=(* This is a mess. *)letpage=Odoc_model.Lang.Page.{name;content;digest}inletpage=Odoc_xref.Lookup.lookup_pagepageinletenv=Env.buildenv(`Pagepage)inOdoc_xref.resolve_page(Env.resolverenv)page>>=funresolved->Page.saveoutputresolved;Ok()inFs.File.readinput>>=funstr->matchOdoc_loader.read_stringnamelocationstrwith|Errore->Error(`Msg(Odoc_model.Error.to_stringe))|Ok`Stop->resolve[](* TODO: Error? *)|Ok(`Docscontent)->resolvecontent