123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104openResulttypefull_location_payload={location:Location_.span;message:string;}typefilename_only_payload={file:string;message:string;}typet=[|`With_full_locationoffull_location_payload|`With_filename_onlyoffilename_only_payload|`Without_locationofstring]letfullmessagelocation=`With_full_location{location;message}letfilename_onlymessagefile=`With_filename_only{file;message}(** Only used internally *)letwithout_locationmessage=`Without_locationmessageletmake?suggestionformat=format|>Printf.ksprintf(funmessage->matchsuggestionwith|None->fullmessage|Somesuggestion->full(message^"\nSuggestion: "^suggestion))letto_string=function|`With_full_location{location;message}->letlocation_string=iflocation.start.line=location.end_.linethenPrintf.sprintf"line %i, characters %i-%i"location.start.linelocation.start.columnlocation.end_.columnelsePrintf.sprintf"line %i, character %i to line %i, character %i"location.start.linelocation.start.columnlocation.end_.linelocation.end_.columninPrintf.sprintf"File \"%s\", %s:\n%s"location.filelocation_stringmessage|`With_filename_only{file;message}->Printf.sprintf"File \"%s\":\n%s"filemessage|`Without_locationmessage->messageexceptionConveyed_by_exceptionoftletraise_exceptionerror=raise(Conveyed_by_exceptionerror)letto_exception=function|Okv->v|Errorerror->raise_exceptionerrorletcatchf=tryOk(f())withConveyed_by_exceptionerror->Errorerrortype'awith_warnings={value:'a;warnings:tlist;}typewarning_accumulator=tlistrefletaccumulate_warningsf=letwarnings=ref[]inletvalue=fwarningsin{value;warnings=List.rev!warnings}letwarningaccumulatorerror=accumulator:=error::!accumulatorletwarn_error=reffalse(* TODO This is a temporary measure until odoc is ported to handle warnings
throughout. *)letshed_warningswith_warnings=with_warnings.warnings|>List.iter(funwarning->warning|>to_string|>prerr_endline);if!warn_error&&with_warnings.warnings<>[]thenraise_exception(without_location"Warnings have been generated.");with_warnings.valueletset_warn_errorb=warn_error:=b