123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172openImporttypet=Astlib.Location.Error.tletto_extension(error:Astlib.Location.Error.t)=letopenAstlib.Location.ErrorinletopenAst_helperinifnot(is_well_formederror)thenraise(Invalid_argument"to_extension: expected kind Report_error");letsub_msgs=sub_msgserrorinletmain_msg=main_msgerrorinleterr_extension_nameloc={Location.loc;txt="ocaml.error"}inletmk_string_constantx=Str.eval(Exp.constant(Const.stringx))inletextension_of_sub_msg(sub_msg:stringLocation.loc)=Str.extension(err_extension_namesub_msg.loc,PStr[mk_string_constantsub_msg.txt])in(err_extension_namemain_msg.loc,Parsetree.PStr(mk_string_constantmain_msg.txt::List.mapextension_of_sub_msgsub_msgs))letregister_error_of_exn=Astlib.Location.register_error_of_exnletmessageerror=let{Astlib.Location.txt;_}=Astlib.Location.Error.main_msgerrorintxtletset_message=Astlib.Location.Error.set_main_msgletmake~loctxt~sub=letsub=List.map(fun(loc,txt)->{Astlib.Location.loc;txt})subinAstlib.Location.Error.make~sub{loc;txt}letupdate_loc=Astlib.Location.Error.set_main_locletget_locationerror=let{Astlib.Location.loc;_}=Astlib.Location.Error.main_msgerrorinlocletof_exn=Astlib.Location.Error.of_exnletraiseerror=raise(Astlib.Location.Errorerror)letof_extension(extension:Ast.extension)=letopenParsetreeinletparse_msg=function|{pstr_desc=Pstr_eval({pexp_desc=Pexp_constant(Pconst_string(msg,_,_));_},[]);_;}->msg|_->"ppxlib: failed to extract message in ocaml.error"inletparse_sub_msg=function|{pstr_desc=Pstr_extension(({txt="error"|"ocaml.error";loc},PStr[msg]),[]);_;}->(loc,parse_msgmsg)|{pstr_loc=loc;_}->(loc,"ppxlib: failed to parse ocaml.error sub messages")inmatchextensionwith|{txt="error"|"ocaml.error";loc},PStr(main::sub)->letmain=parse_msgmaininletsub=List.mapparse_sub_msgsubinSome(make~locmain~sub)|_->None