12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552(**************************************************************************)(* *)(* OCaml *)(* *)(* Thomas Gazagnaire, OCamlPro *)(* Fabrice Le Fessant, INRIA Saclay *)(* Hongbo Zhang, University of Pennsylvania *)(* *)(* Copyright 2007 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Original Code from Ber-metaocaml, modified for 3.12.0 and fixed *)(* Printing code expressions *)(* Authors: Ed Pizzi, Fabrice Le Fessant *)(* Extensive Rewrite: Hongbo Zhang: University of Pennsylvania *)(* TODO more fine-grained precedence pretty-printing *)openAsttypesopenFormatopenLocationopenLongidentopenParsetreeletprefix_symbols=['!';'?';'~']letinfix_symbols=['=';'<';'>';'@';'^';'|';'&';'+';'-';'*';'/';'$';'%';'#'](* type fixity = Infix| Prefix *)letspecial_infix_strings=["asr";"land";"lor";"lsl";"lsr";"lxor";"mod";"or";":=";"!=";"::"]letletops=String.lengths>3&&s.[0]='l'&&s.[1]='e'&&s.[2]='t'&&List.mems.[3]infix_symbolsletandops=String.lengths>3&&s.[0]='a'&&s.[1]='n'&&s.[2]='d'&&List.mems.[3]infix_symbols(* determines if the string is an infix string.
checks backwards, first allowing a renaming postfix ("_102") which
may have resulted from Pexp -> Texp -> Pexp translation, then checking
if all the characters in the beginning of the string are valid infix
characters. *)letfixity_of_string=function|""->`Normal|swhenList.memsspecial_infix_strings->`Infixs|swhenList.mems.[0]infix_symbols->`Infixs|swhenList.mems.[0]prefix_symbols->`Prefixs|swhens.[0]='.'->`Mixfixs|swhenletops->`Letops|swhenandops->`Andops|_->`Normalletview_fixity_of_exp=function|{pexp_desc=Pexp_ident{txt=Lidentl;_};pexp_attributes=[]}->fixity_of_stringl|_->`Normalletis_infix=function`Infix_->true|_->falseletis_mixfix=function`Mixfix_->true|_->falseletis_kwdop=function`Letop_|`Andop_->true|_->falseletfirst_iscstr=str<>""&&str.[0]=cletlast_iscstr=str<>""&&str.[String.lengthstr-1]=cletfirst_is_incsstr=str<>""&&List.memstr.[0]cs(* which identifiers are in fact operators needing parentheses *)letneeds_parenstxt=letfix=fixity_of_stringtxtinis_infixfix||is_mixfixfix||is_kwdopfix||first_is_inprefix_symbolstxt(* some infixes need spaces around parens to avoid clashes with comment
syntax *)letneeds_spacestxt=first_is'*'txt||last_is'*'txtlettyvar_of_names=ifString.lengths>=2&&s.[1]='\''then(* without the space, this would be parsed as
a character literal *)"' "^selseifLexer.is_keywordsthen"'\\#"^selseifString.equals"_"thenselse"'"^s(* Unlike upstream, we call this module [Doc_internal] and define [Doc] at the
end of the file to include [jkind_annotation]. *)moduleDoc_internal=struct(* Turn an arbitrary variable name into a valid OCaml identifier by adding \#
in case it is a keyword, or parenthesis when it is an infix or prefix
operator. *)letident_of_nameppftxt=letformat:(_,_,_)format=ifLexer.is_keywordtxtthen"\\#%s"elseifnot(needs_parenstxt)then"%s"elseifneeds_spacestxtthen"(@;%s@;)"else"(%s)"inFormat_doc.fprintfppfformattxtletprotect_longidentppfprint_longidentlongprefixtxt=ifnot(needs_parenstxt)thenFormat_doc.fprintfppf"%a.%a"print_longidentlongprefixident_of_nametxtelseifneeds_spacestxtthenFormat_doc.fprintfppf"%a.(@;%s@;)"print_longidentlongprefixtxtelseFormat_doc.fprintfppf"%a.(%s)"print_longidentlongprefixtxtletreclongidentf=function|Lidents->ident_of_namefs|Ldot(y,s)->protect_longidentflongidentys|Lapply(y,s)->Format_doc.fprintff"%a(%a)"longidentylongidentslettyvarppfs=Format_doc.fprintfppf"%s"(tyvar_of_names)endletlongidentppfl=Format_doc.compatDoc_internal.longidentppflletident_of_nameppfi=Format_doc.compatDoc_internal.ident_of_nameppfiletis_curry_attrattr=attr.attr_name.txt=Builtin_attributes.curry_attr_nameletsplit_out_curry_attrattrs=letcurry,non_curry=List.partitionis_curry_attrattrsinletis_curry=matchcurrywith|[]->false|_::_->trueinis_curry,non_currytypespace_formatter=(unit,Format.formatter,unit)formatletoverride=function|Override->"!"|Fresh->""(* variance encoding: need to sync up with the [parser.mly] *)lettype_variance=function|NoVariance->""|Covariant->"+"|Contravariant->"-"lettype_injectivity=function|NoInjectivity->""|Injective->"!"typeconstruct=[`consofexpressionlist|`listofexpressionlist|`nil|`normal|`simpleofLongident.t|`tuple|`btrue|`bfalse]letview_exprx=matchx.pexp_descwith|Pexp_construct({txt=Lident"()";_},_)->`tuple|Pexp_construct({txt=Lident"true";_},_)->`btrue|Pexp_construct({txt=Lident"false";_},_)->`bfalse|Pexp_construct({txt=Lident"[]";_},_)->`nil|Pexp_construct({txt=Lident"::";_},Some_)->letrecloopexpacc=matchexpwith|{pexp_desc=Pexp_construct({txt=Lident"[]";_},_);pexp_attributes=[]}->(List.revacc,true)|{pexp_desc=Pexp_construct({txt=Lident"::";_},Some({pexp_desc=Pexp_tuple([None,e1;None,e2]);pexp_attributes=[]}));pexp_attributes=[]}->loope2(e1::acc)|e->(List.rev(e::acc),false)inlet(ls,b)=loopx[]inifbthen`listlselse`consls|Pexp_construct(x,None)->`simple(x.txt)|_->`normalletis_simple_construct:construct->bool=function|`nil|`tuple|`list_|`simple_|`btrue|`bfalse->true|`cons_|`normal->falseletpp=fprintftypectxt={pipe:bool;semi:bool;ifthenelse:bool;functionrhs:bool;}letreset_ctxt={pipe=false;semi=false;ifthenelse=false;functionrhs=false}letunder_pipectxt={ctxtwithpipe=true}letunder_semictxt={ctxtwithsemi=true}letunder_ifthenelsectxt={ctxtwithifthenelse=true}letunder_functionrhsctxt={ctxtwithfunctionrhs=true}(*
let reset_semi ctxt = { ctxt with semi=false }
let reset_ifthenelse ctxt = { ctxt with ifthenelse=false }
let reset_pipe ctxt = { ctxt with pipe=false }
*)letlist:'a.?sep:space_formatter->?first:space_formatter->?last:space_formatter->(Format.formatter->'a->unit)->Format.formatter->'alist->unit=fun?sep?first?lastfufxs->letfirst=matchfirstwithSomex->x|None->("":_format6)andlast=matchlastwithSomex->x|None->("":_format6)andsep=matchsepwithSomex->x|None->("@ ":_format6)inletauxf=function|[]->()|[x]->fufx|xs->letrecloopf=function|[x]->fufx|x::xs->fufx;ppfsep;loopfxs;|_->assertfalseinbeginppffirst;loopfxs;ppflast;endinauxfxsletoption:'a.?first:space_formatter->?last:space_formatter->(Format.formatter->'a->unit)->Format.formatter->'aoption->unit=fun?first?lastfufa->letfirst=matchfirstwithSomex->x|None->("":_format6)andlast=matchlastwithSomex->x|None->("":_format6)inmatchawith|None->()|Somex->ppffirst;fufx;ppflastletparen:'a.?first:space_formatter->?last:space_formatter->bool->(Format.formatter->'a->unit)->Format.formatter->'a->unit=fun?(first=("":_format6))?(last=("":_format6))bfufx->ifbthen(ppf"(";ppffirst;fufx;ppflast;ppf")")elsefufxletlongident_locfx=ppf"%a"longidentx.txtletconstantf=function|Pconst_chari->ppf"%C"i|Pconst_untagged_chari->ppf"#%C"i|Pconst_string(i,_,None)->ppf"%S"i|Pconst_string(i,_,Somedelim)->ppf"{%s|%s|%s}"delimidelim|Pconst_integer(i,None)->paren(first_is'-'i)(funf->ppf"%s")fi|Pconst_integer(i,Somem)->paren(first_is'-'i)(funf(i,m)->ppf"%s%c"im)f(i,m)|Pconst_float(i,None)->paren(first_is'-'i)(funf->ppf"%s")fi|Pconst_float(i,Somem)->paren(first_is'-'i)(funf(i,m)->ppf"%s%c"im)f(i,m)|Pconst_unboxed_float(x,None)->paren(first_is'-'x)(funf->ppf"%s")f(Misc.format_as_unboxed_literalx)|Pconst_unboxed_float(x,Somesuffix)|Pconst_unboxed_integer(x,suffix)->paren(first_is'-'x)(funf(x,suffix)->ppf"%s%c"xsuffix)f(Misc.format_as_unboxed_literalx,suffix)letboolf=function|false->ppf"false"|true->ppf"true"(* trailing space*)letmutable_flagf=function|Immutable->()|Mutable->ppf"mutable@;"letvirtual_flagf=function|Concrete->()|Virtual->ppf"virtual@;"(* trailing space added *)letrec_flagfrf=matchrfwith|Nonrecursive->()|Recursive->ppf"rec "letnonrec_flagfrf=matchrfwith|Nonrecursive->ppf"nonrec "|Recursive->()letdirection_flagf=function|Upto->ppf"to@ "|Downto->ppf"downto@ "letprivate_flagf=function|Public->()|Private->ppf"private@ "letiter_locfctxt{txt;loc=_}=fctxttxtletconstant_stringfs=ppf"%S"slettyvarppfv=Format_doc.compatDoc_internal.tyvarppfvletstring_locppfx=fprintfppf"%s"x.txtletstring_quotfx=ppf"`%a"ident_of_namex(* new mode and modality syntax *)letmodef{txt=Modes;_}=pp_print_stringfsletmodesfm=pp_print_list~pp_sep:(funf()->ppf" ")modefmletoptional_at_modesfm=matchmwith|[]->()|m->ppf" %@ %a"modesmletmodalityfm=let{txt=Modalitytxt;_}=minpp_print_stringftxtletmodalitiesfm=pp_print_list~pp_sep:(funf()->ppf" ")modalityfmletoptional_modalities?(pre=fun_()->())?(post=fun_()->())fm=matchmwith|[]->()|m->pref();ppf"%a"modalitiesm;postf()letoptional_space_atat_modalitiesfm=letpref()=Format.fprintff"@ %@%@@ "inoptional_modalities~prefmletoptional_atat_modalities_newlinefm=letpref()=Format.fprintff"%@%@@ "inoptional_modalities~pre~post:pp_print_newlinefmletmodalities_typeptyctxtfpca=letm=pca.pca_modalitiesinppf"%a%a"(ptyctxt)pca.pca_typeoptional_space_atat_modalitiesmletinclude_kindf=function|Functor->ppf"@ functor"|Structure->()typefunction_delimiter=Arrow|Equals(* c ['a,'b] *)letrecclass_params_deff=function|[]->()|l->ppf"[%a] "(* space *)(listtype_param~sep:",")landcore_type1_with_optional_modesptyctxtf(c,m)=matchmwith|[]->ptyctxtfc|_::_->ppf"%a%a"(core_type1ctxt)coptional_at_modesmandtype_with_labelctxtf(label,c,mode)=matchlabelwith|Nolabel->core_type1_with_optional_modescore_type1ctxtf(c,mode)(* otherwise parenthesize *)|Labelleds->ppf"%a:%a"ident_of_names(core_type1_with_optional_modescore_type1ctxt)(c,mode)|Optionals->ppf"?%a:%a"ident_of_names(core_type1_with_optional_modescore_type1ctxt)(c,mode)andjkind_annotation?(nested=false)ctxtfk=matchk.pjka_descwith|Pjk_default->ppf"_"|Pjk_abbreviation(s,sa)->longident_locfs;List.iter(funa->ppf" %s"a.Location.txt)sa|Pjk_mod(t,modes)->beginmatchmodeswith|[]->Misc.fatal_error"malformed jkind annotation"|_::_->Misc.pp_parens_ifnested(funf(t,modes)->ppf"%a mod %a"(jkind_annotation~nested:truectxt)t(pp_print_list~pp_sep:pp_print_spacemode)modes)f(t,modes)end|Pjk_with(t,ty,modalities)->Misc.pp_parens_ifnested(funf(t,ty,modalities)->ppf"%a with %a%a"(jkind_annotation~nested:truectxt)t(core_typectxt)tyoptional_space_atat_modalitiesmodalities;)f(t,ty,modalities)|Pjk_kind_ofty->ppf"(kind_of_ %a)"(core_typectxt)ty|Pjk_productts->Misc.pp_parens_ifnested(funfts->ppf"@[%a@]"(list(jkind_annotation~nested:truectxt)~sep:"@ & ")ts)ftsandtyvar_jkindtyvarf(str,jkind)=matchjkindwith|None->tyvarfstr|Somelay->ppf"(%a : %a)"tyvarstr(jkind_annotationreset_ctxt)layandtyvar_loc_jkindtyvarf(str,jkind)=tyvar_jkindtyvarf(str.txt,jkind)andtyvar_loc_reprtyvarfstr=ppf"(repr_@ %a)"tyvarstr.txtandtyvar_loc_option_jkindf(str,jkind)=matchjkindwith|None->tyvar_loc_optionfstr|Somejkind->ppf"(%a : %a)"tyvar_loc_optionstr(jkind_annotationreset_ctxt)jkindandname_jkindf(name,jkind)=matchjkindwith|None->ident_of_namefname|Somejkind->ppf"(%a : %a)"ident_of_namename(jkind_annotationreset_ctxt)jkindandname_loc_jkindf(str,jkind)=name_jkindf(str.txt,jkind)andcore_typectxtfx=ifx.ptyp_attributes<>[]thenbeginppf"((%a)%a)"(core_typectxt){xwithptyp_attributes=[]}(attributesctxt)x.ptyp_attributesendelsematchx.ptyp_descwith|Ptyp_arrow(l,ct1,ct2,m1,m2)->ppf"@[<2>%a@;->@;%a@]"(* FIXME remove parens later *)(type_with_labelctxt)(l,ct1,m1)(return_typectxt)(ct2,m2)|Ptyp_alias(ct,s,j)->ppf"@[<2>%a@;as@;%a@]"(core_type1ctxt)cttyvar_loc_option_jkind(s,j)|Ptyp_poly([],ct)|Ptyp_repr([],ct)|Ptyp_newlayout([],ct)->core_typectxtfct|Ptyp_poly(sl,ct)->ppf"@[<2>%a%a@]"(funfl->matchlwith|[]->()|_->ppf"%a@;.@;"(list(tyvar_loc_jkindtyvar)~sep:"@;")l)sl(core_typectxt)ct|Ptyp_repr(lv,ct)->ppf"@[<2>%a%a@]"(funfl->matchlwith|[]->()|_->ppf"%a@;.@;"(list(tyvar_loc_reprtyvar)~sep:"@;")l)lv(core_typectxt)ct|Ptyp_newlayout(lv,ct)->ppf"@[<2>layout_@;%a.@;%a@]"(liststring_loc~sep:"@;")lv(core_typectxt)ct|Ptyp_of_kindjkind->ppf"@[(type@ :@ %a)@]"(jkind_annotationreset_ctxt)jkind|_->ppf"@[<2>%a@]"(core_type1ctxt)xandcore_type1ctxtfx=ifx.ptyp_attributes<>[]thencore_typectxtfxelsematchx.ptyp_descwith|Ptyp_anyjkind->tyvar_loc_option_jkindf(None,jkind)|Ptyp_var(s,jkind)->(tyvar_jkindtyvar)f(s,jkind)|Ptyp_tupletl->ppf"(%a)"(list(labeled_core_type1ctxt)~sep:"@;*@;")tl|Ptyp_unboxed_tuplel->core_type1_labeled_tuplectxtf~unboxed:truel|Ptyp_constr(li,l)->ppf(* "%a%a@;" *)"%a%a"(funfl->matchlwith|[]->()|[x]->ppf"%a@;"(core_type1ctxt)x|_->list~first:"("~last:")@;"(core_typectxt)~sep:",@;"fl)llongident_locli|Ptyp_variant(l,closed,low)->letfirst_is_inherit=matchlwith|{Parsetree.prf_desc=Rinherit_}::_->true|_->falseinlettype_variant_helperfx=matchx.prf_descwith|Rtag(l,_,ctl)->ppf"@[<2>%a%a@;%a@]"(iter_locstring_quot)l(funfl->matchlwith|[]->()|_->ppf"@;of@;%a"(list(core_typectxt)~sep:"&")ctl)ctl(attributesctxt)x.prf_attributes|Rinheritct->core_typectxtfctinppf"@[<2>[%a%a]@]"(funfl->matchl,closedwith|[],Closed->()|[],Open->ppf">"(* Cf #7200: print [>] correctly *)|_->ppf"%s@;%a"(match(closed,low)with|(Closed,None)->iffirst_is_inheritthen" |"else""|(Closed,Some_)->"<"(* FIXME desugar the syntax sugar*)|(Open,_)->">")(listtype_variant_helper~sep:"@;<1 -2>| ")l)l(funflow->matchlowwith|Some[]|None->()|Somexs->ppf">@ %a"(liststring_quot)xs)low|Ptyp_object(l,o)->letcore_field_typefx=matchx.pof_descwith|Otag(l,ct)->(* Cf #7200 *)ppf"@[<hov2>%a: %a@ %a@ @]"ident_of_namel.txt(core_typectxt)ct(attributesctxt)x.pof_attributes|Oinheritct->ppf"@[<hov2>%a@ @]"(core_typectxt)ctinletfield_varf=function|Asttypes.Closed->()|Asttypes.Open->matchlwith|[]->ppf".."|_->ppf" ;.."inppf"@[<hov2><@ %a%a@ > @]"(listcore_field_type~sep:";")lfield_varo(* Cf #7200 *)|Ptyp_class(li,l)->(*FIXME*)ppf"@[<hov2>%a@;#%a@]"(list(core_typectxt)~sep:","~first:"("~last:")")llongident_locli|Ptyp_package(lid,cstrs)->letauxf(s,ct)=ppf"type %a@ =@ %a"longident_locs(core_typectxt)ctin(matchcstrswith|[]->ppf"@[<hov2>(module@ %a)@]"longident_loclid|_->ppf"@[<hov2>(module@ %a@ with@ %a)@]"longident_loclid(listaux~sep:"@ and@ ")cstrs)|Ptyp_open(li,ct)->ppf"@[<hov2>%a.(%a)@]"longident_locli(core_typectxt)ct|Ptyp_quotet->ppf"@[<hov2><[%a]>@]"(core_typectxt)t|Ptyp_splicet->ppf"@[<hov2>$(%a)@]"(core_typectxt)t|Ptyp_extensione->extensionctxtfe|(Ptyp_arrow_|Ptyp_alias_|Ptyp_poly_|Ptyp_repr_|Ptyp_newlayout_|Ptyp_of_kind_)->parentrue(core_typectxt)fxandcore_type2ctxtfx=ifx.ptyp_attributes<>[]thencore_typectxtfxelsematchx.ptyp_descwith|Ptyp_poly(sl,ct)->ppf"@[<2>%a%a@]"(funfl->matchlwith|[]->()|_->ppf"%a@;.@;"(list(tyvar_loc_jkindtyvar)~sep:"@;")l)sl(core_type1ctxt)ct|_->core_type1ctxtfxandtyvar_optionf=function|None->ppf"_"|Somename->tyvarfnameandtyvar_loc_optionfstr=tyvar_optionf(Option.mapLocation.get_txtstr)andcore_type1_labeled_tuplectxtf~unboxedtl=ppf"%s(%a)"(ifunboxedthen"#"else"")(list(labeled_core_type1ctxt)~sep:"@;*@;")tlandlabeled_core_type1ctxtf(label,ty)=beginmatchlabelwith|None->()|Somes->ppf"%s:"send;core_type1ctxtftyandreturn_typectxtf(x,m)=letis_curry,ptyp_attributes=split_out_curry_attrx.ptyp_attributesinletx={xwithptyp_attributes}inifis_currythencore_type1_with_optional_modescore_type1ctxtf(x,m)elsecore_type1_with_optional_modescore_typectxtf(x,m)andcore_type2_with_optional_modesctxtf(ty,modes)=matchmodeswith|[]->core_typectxtfty|_::_->ppf"%a%a"(core_type2ctxt)tyoptional_at_modesmodes(********************pattern********************)(* be cautious when use [pattern], [pattern1] is preferred *)andpatternctxtfx=ifx.ppat_attributes<>[]thenbeginppf"((%a)%a)"(patternctxt){xwithppat_attributes=[]}(attributesctxt)x.ppat_attributesendelsematchx.ppat_descwith|Ppat_alias(p,s)->ppf"@[<2>%a@;as@;%a@]"(patternctxt)pident_of_names.txt|_->pattern_orctxtfxandpattern_orctxtfx=letrecleft_associativexacc=matchxwith|{ppat_desc=Ppat_or(p1,p2);ppat_attributes=[]}->left_associativep1(p2::acc)|x->x::accinmatchleft_associativex[]with|[]->assertfalse|[x]->pattern1ctxtfx|orpats->ppf"@[<hov0>%a@]"(list~sep:"@ | "(pattern1ctxt))orpatsandpattern1ctxt(f:Format.formatter)(x:pattern):unit=letrecpattern_list_helperfp=matchpwith|{ppat_desc=Ppat_construct({txt=Lident("::");_},Some([],inner_pat));ppat_attributes=[]}->beginmatchinner_pat.ppat_descwith|Ppat_tuple([None,pat1;None,pat2],Closed)->ppf"%a::%a"(simple_patternctxt)pat1pattern_list_helperpat2(*RA*)|_->pattern1ctxtfpend|_->pattern1ctxtfpinifx.ppat_attributes<>[]thenpatternctxtfxelsematchx.ppat_descwith|Ppat_variant(l,Somep)->ppf"@[<2>`%a@;%a@]"ident_of_namel(simple_patternctxt)p|Ppat_construct(({txt=Lident("()"|"[]"|"true"|"false");_}),_)->simple_patternctxtfx|Ppat_construct(({txt;_}asli),po)->(* FIXME The third field always false *)iftxt=Lident"::"thenppf"%a"pattern_list_helperxelse(matchpowith|Some([],x)->ppf"%a@;%a"longident_locli(simple_patternctxt)x|Some(vl,x)->ppf"%a@ (type %a)@;%a"longident_locli(list~sep:"@ "name_loc_jkind)vl(simple_patternctxt)x|None->ppf"%a"longident_locli)|_->simple_patternctxtfxandlabeled_pattern1ctxt(f:Format.formatter)(label,x):unit=letsimple_name=matchxwith|{ppat_desc=Ppat_var{txt=s;_};ppat_attributes=[];_}->Somes|_->Noneinmatchlabel,simple_namewith|None,_->pattern1ctxtfx|Somelbl,Somesimple_namewhenString.equalsimple_namelbl->ppf"~%s"lbl|Somelbl,_->ppf"~%s:"lbl;pattern1ctxtfxandsimple_patternctxt(f:Format.formatter)(x:pattern):unit=ifx.ppat_attributes<>[]thenpatternctxtfxelsematchx.ppat_descwith|Ppat_construct(({txt=Lident("()"|"[]"|"true"|"false"asx);_}),None)->ppf"%s"x|Ppat_any->ppf"_";|Ppat_var({txt=txt;_})->ident_of_nameftxt|Ppat_array(mut,l)->letpunct=matchmutwith|Mutable->'|'|Immutable->':'inppf"@[<2>[%c%a%c]@]"punct(list(pattern1ctxt)~sep:";")lpunct|Ppat_unpack{txt=None}->ppf"(module@ _)@ "|Ppat_unpack{txt=Somes}->ppf"(module@ %s)@ "s|Ppat_typeli->ppf"#%a"longident_locli|Ppat_record(l,closed)->record_patternctxtf~unboxed:falselclosed|Ppat_record_unboxed_product(l,closed)->record_patternctxtf~unboxed:truelclosed|Ppat_unboxed_unit->ppf"#()"|Ppat_unboxed_boolb->ppf"#%a"boolb|Ppat_tuple(l,closed)->labeled_tuple_patternctxtf~unboxed:falselclosed|Ppat_unboxed_tuple(l,closed)->labeled_tuple_patternctxtf~unboxed:truelclosed|Ppat_constant(c)->ppf"%a"constantc|Ppat_interval(c1,c2)->ppf"%a..%a"constantc1constantc2|Ppat_variant(l,None)->ppf"`%a"ident_of_namel|Ppat_constraint(p,ct,_)->ppf"@[<2>(%a@;:@;%a)@]"(pattern1ctxt)p(core_typectxt)(Option.getct)|Ppat_lazyp->ppf"@[<2>(lazy@;%a)@]"(simple_patternctxt)p|Ppat_exceptionp->ppf"@[<2>exception@;%a@]"(pattern1ctxt)p|Ppat_extensione->extensionctxtfe|Ppat_open(lid,p)->letwith_paren=matchp.ppat_descwith|Ppat_array_|Ppat_record_|Ppat_record_unboxed_product_|Ppat_construct(({txt=Lident("()"|"[]"|"true"|"false");_}),None)->false|_->trueinppf"@[<2>%a.%a @]"longident_loclid(parenwith_paren@@pattern1ctxt)p|_->parentrue(patternctxt)fxandrecord_patternctxtf~unboxedlclosed=letlongident_x_patternf(li,p)=match(li,p)with|({txt=Lidents;_},{ppat_desc=Ppat_var{txt;_};ppat_attributes=[];_})whens=txt->ppf"@[<2>%a@]"longident_locli|_->ppf"@[<2>%a@;=@;%a@]"longident_locli(pattern1ctxt)pinlethash=ifunboxedthen"#"else""inmatchclosedwith|Closed->ppf"@[<2>%s{@;%a@;}@]"hash(listlongident_x_pattern~sep:";@;")l|Open->ppf"@[<2>%s{@;%a;_}@]"hash(listlongident_x_pattern~sep:";@;")landlabeled_tuple_patternctxtf~unboxedlclosed=letclosed_flagppf=function|Closed->()|Open->ppppf",@;.."inppf"@[<1>%s(%a%a)@]"(ifunboxedthen"#"else"")(list~sep:",@;"(labeled_pattern1ctxt))lclosed_flagclosed(** for special treatment of modes in labeled expressions *)andpattern2ctxtfp=matchp.ppat_descwith|Ppat_constraint(p,ct,m)->beginmatchctwith|Somect->ppf"@[<2>%a@;:@;%a@]"(simple_patternctxt)p(core_type2_with_optional_modesctxt)(ct,m)|None->ppf"@[<2>%a%a@]"(simple_patternctxt)poptional_at_modesmend|_->pattern1ctxtfp(** for special treatment of modes in labeled expressions *)andsimple_pattern1ctxtfp=matchp.ppat_descwith|Ppat_constraint_->ppf"(%a)"(pattern2ctxt)p|_->simple_patternctxtfpandlabel_expctxtf(l,opt,p)=matchlwith|Nolabel->(* single case pattern parens needed here *)ppf"%a"(simple_pattern1ctxt)p|Optionalrest->beginmatchpwith|{ppat_desc=Ppat_var{txt;_};ppat_attributes=[]}whentxt=rest->(matchoptwith|Someo->ppf"?(%a=@;%a)"ident_of_namerest(expressionctxt)o|None->ppf"?%a"ident_of_namerest)|_->(matchoptwith|Someo->ppf"?%a:(%a=@;%a)@;"ident_of_namerest(pattern2ctxt)p(expressionctxt)o|None->ppf"?%a:%a@;"ident_of_namerest(simple_pattern1ctxt)p)end|Labelledl->matchpwith|{ppat_desc=Ppat_var{txt;_};ppat_attributes=[]}whentxt=l->ppf"~%a"ident_of_namel|_->ppf"~%a:%a"ident_of_namel(simple_pattern1ctxt)pandsugar_exprctxtfe=ife.pexp_attributes<>[]thenfalseelsematche.pexp_descwith|Pexp_apply({pexp_desc=Pexp_ident{txt=id;_};pexp_attributes=[];_},args)whenList.for_all(fun(lab,_)->lab=Nolabel)args->beginletprint_indexopapath_prefixassignleftseprightprint_indexindicesrem_args=letprint_pathppf=function|None->()|Somem->ppppf".%a"longidentminmatchassign,rem_argswith|false,[]->ppf"@[%a%a%s%a%s@]"(simple_exprctxt)aprint_pathpath_prefixleft(list~sepprint_index)indicesright;true|true,[v]->ppf"@[%a%a%s%a%s@ <-@;<1 2>%a@]"(simple_exprctxt)aprint_pathpath_prefixleft(list~sepprint_index)indicesright(simple_exprctxt)v;true|_->falseinmatchid,List.mapsndargswith|Lident"!",[e]->ppf"@[<hov>!%a@]"(simple_exprctxt)e;true|Ldot(path,("get"|"set"asfunc)),a::other_args->beginletassign=func="set"inletprint=print_indexopaNoneassigninmatchpath,other_argswith|Lident"Array",i::rest->print".("""")"(expressionctxt)[i]rest|Lident"String",i::rest->print".[""""]"(expressionctxt)[i]rest|Ldot(Lident"Bigarray","Array1"),i1::rest->print".{"",""}"(simple_exprctxt)[i1]rest|Ldot(Lident"Bigarray","Array2"),i1::i2::rest->print".{"",""}"(simple_exprctxt)[i1;i2]rest|Ldot(Lident"Bigarray","Array3"),i1::i2::i3::rest->print".{"",""}"(simple_exprctxt)[i1;i2;i3]rest|Ldot(Lident"Bigarray","Genarray"),{pexp_desc=Pexp_array(_,indexes);pexp_attributes=[]}::rest->print".{"",""}"(simple_exprctxt)indexesrest|_->falseend|(Lidents|Ldot(_,s)),a::i::restwhenfirst_is'.'s->(* extract operator:
assignment operators end with [right_bracket ^ "<-"],
access operators end with [right_bracket] directly
*)letmulti_indices=String.containss';'inleti=matchi.pexp_descwith|Pexp_array(_,l)whenmulti_indices->l|_->[i]inletassign=last_is'-'sinletkind=(* extract the right end bracket *)letn=String.lengthsinifassignthens.[n-3]elses.[n-1]inletleft,right=matchkindwith|')'->'(',")"|']'->'[',"]"|'}'->'{',"}"|_->assertfalseinletpath_prefix=matchidwith|Ldot(m,_)->Somem|_->Noneinletleft=String.subs0(1+String.indexsleft)inprint_indexopapath_prefixassignleft";"right(ifmulti_indicesthenexpressionctxtelsesimple_exprctxt)irest|_->falseend|_->falseandexpressionctxtfx=ifx.pexp_attributes<>[]thenppf"((%a)@,%a)"(expressionctxt){xwithpexp_attributes=[]}(attributesctxt)x.pexp_attributeselsematchx.pexp_descwith|Pexp_function_|Pexp_match_|Pexp_try_|Pexp_sequence_|Pexp_newtype_whenctxt.pipe||ctxt.semi->parentrue(expressionreset_ctxt)fx|Pexp_ifthenelse_|Pexp_sequence_whenctxt.ifthenelse->parentrue(expressionreset_ctxt)fx|Pexp_let_|Pexp_letmodule_|Pexp_open_|Pexp_letexception_|Pexp_letop_whenctxt.semi->parentrue(expressionreset_ctxt)fx|Pexp_newtype(lid,jkind,e)->ppf"@[<2>fun@;(type@;%a)@;%a@]"name_jkind(lid.txt,jkind)(pp_print_pexp_newtypectxt"->")e|Pexp_function(params,constraint_,body)->beginmatchparams,constraint_with(* Omit [fun] if there are no params. *)|[],{ret_type_constraint=None;ret_mode_annotations=[];_}->(* If function cases are a direct body of a function,
the function node should be wrapped in parens so
it doesn't become part of the enclosing function. *)letshould_paren=matchbodywith|Pfunction_cases_->ctxt.functionrhs|Pfunction_body_->falseinletctxt'=ifshould_parenthenreset_ctxtelsectxtinppf"@[<2>%a@]"(parenshould_paren(function_bodyctxt'))body|[],constraint_->ppf"@[<2>(%a%a)@]"(function_bodyctxt)body(function_constraint~followed_by_arrow:falsectxt)constraint_|_::_,_->ppf"@[<2>fun@;%t@]"(funf->function_params_then_bodyctxtfparamsconstraint_body~delimiter:Arrow)end|Pexp_match(e,l)->ppf"@[<hv0>@[<hv0>@[<2>match %a@]@ with@]%a@]"(expressionreset_ctxt)e(case_listctxt)l|Pexp_try(e,l)->ppf"@[<0>@[<hv2>try@ %a@]@ @[<0>with%a@]@]"(* "try@;@[<2>%a@]@\nwith@\n%a"*)(expressionreset_ctxt)e(case_listctxt)l|Pexp_let(mf,rf,l,e)->(* pp f "@[<2>let %a%a in@;<1 -2>%a@]"
(*no indentation here, a new line*) *)(* rec_flag rf *)(* mutable_flag mf *)ppf"@[<2>%a in@;<1 -2>%a@]"(bindingsreset_ctxt)(mf,rf,l)(expressionctxt)e|Pexp_apply({pexp_desc=Pexp_extension({txt="extension.exclave"},PStr[])},[Nolabel,sbody])->ppf"@[<2>exclave_ %a@]"(expressionctxt)sbody|Pexp_apply(e,l)->beginifnot(sugar_exprctxtfx)thenmatchview_fixity_of_expewith|`Infixs->beginmatchlwith|[(Nolabel,_)asarg1;(Nolabel,_)asarg2]->(* FIXME associativity label_x_expression_param *)ppf"@[<2>%a@;%s@;%a@]"(label_x_expression_paramreset_ctxt)arg1s(label_x_expression_paramctxt)arg2|_->ppf"@[<2>%a %a@]"(simple_exprctxt)e(list(label_x_expression_paramctxt))lend|`Prefixs->lets=ifList.mems["~+";"~-";"~+.";"~-."]&&(matchlwith(* See #7200: avoid turning (~- 1) into (- 1) which is
parsed as an int literal *)|[(_,{pexp_desc=Pexp_constant_})]->false|_->true)thenString.subs1(String.lengths-1)elsesinbeginmatchlwith|[(Nolabel,x)]->ppf"@[<2>%s@;%a@]"s(simple_exprctxt)x|_->ppf"@[<2>%a %a@]"(simple_exprctxt)e(list(label_x_expression_paramctxt))lend|_->ppf"@[<hov2>%a@]"beginfunf(e,l)->ppf"%a@ %a"(expression2ctxt)e(list(label_x_expression_paramreset_ctxt))l(* reset here only because [function,match,try,sequence]
are lower priority *)end(e,l)end|Pexp_stacke->(* Similar to the common case of [Pexp_apply] *)ppf"@[<hov2>stack_@ %a@]"(expression2reset_ctxt)e|Pexp_construct(li,Someeo)whennot(is_simple_construct(view_exprx))->(* Not efficient FIXME*)(matchview_exprxwith|`consls->list(simple_exprctxt)fls~sep:"@;::@;"|`normal->ppf"@[<2>%a@;%a@]"longident_locli(simple_exprctxt)eo|_->assertfalse)|Pexp_setfield(e1,li,e2)->ppf"@[<2>%a.%a@ <-@ %a@]"(simple_exprctxt)e1longident_locli(simple_exprctxt)e2|Pexp_ifthenelse(e1,e2,eo)->(* @;@[<2>else@ %a@]@] *)letfmt:(_,_,_)format="@[<hv0>@[<2>if@ %a@]@;@[<2>then@ %a@]%a@]"inletexpression_under_ifthenelse=expression(under_ifthenelsectxt)inppffmtexpression_under_ifthenelsee1expression_under_ifthenelsee2(funfeo->matcheowith|Somex->ppf"@;@[<2>else@;%a@]"(expression(under_semictxt))x|None->()(* pp f "()" *))eo|Pexp_sequence_->letrecsequence_helperacc=function|{pexp_desc=Pexp_sequence(e1,e2);pexp_attributes=[]}->sequence_helper(e1::acc)e2|v->List.rev(v::acc)inletlst=sequence_helper[]xinppf"@[<hv>%a@]"(list(expression(under_semictxt))~sep:";@;")lst|Pexp_new(li)->ppf"@[<hov2>new@ %a@]"longident_locli;|Pexp_setvar(s,e)->ppf"@[<hov2>%a@ <-@ %a@]"ident_of_names.txt(expressionctxt)e|Pexp_overridel->(* FIXME *)letstring_x_expressionf(s,e)=ppf"@[<hov2>%a@ =@ %a@]"ident_of_names.txt(expressionctxt)einppf"@[<hov2>{<%a>}@]"(liststring_x_expression~sep:";")l;|Pexp_letmodule(s,me,e)->ppf"@[<hov2>let@ module@ %s@ =@ %a@ in@ %a@]"(Option.values.txt~default:"_")(module_exprreset_ctxt)me(expressionctxt)e|Pexp_letexception(cd,e)->ppf"@[<hov2>let@ exception@ %a@ in@ %a@]"(extension_constructorctxt)cd(expressionctxt)e|Pexp_asserte->ppf"@[<hov2>assert@ %a@]"(simple_exprctxt)e|Pexp_lazy(e)->ppf"@[<hov2>lazy@ %a@]"(simple_exprctxt)e(* Pexp_poly: impossible but we should print it anyway, rather than
assert false *)|Pexp_poly(e,None)->ppf"@[<hov2>!poly!@ %a@]"(simple_exprctxt)e|Pexp_poly(e,Somect)->ppf"@[<hov2>(!poly!@ %a@ : %a)@]"(simple_exprctxt)e(core_typectxt)ct|Pexp_open(o,e)->ppf"@[<2>let open%s %a in@;%a@]"(overrideo.popen_override)(module_exprctxt)o.popen_expr(expressionctxt)e|Pexp_variant(l,Someeo)->ppf"@[<2>`%a@;%a@]"ident_of_namel(simple_exprctxt)eo|Pexp_letop{let_;ands;body}->ppf"@[<2>@[<v>%a@,%a@] in@;<1 -2>%a@]"(binding_opctxt)let_(list~sep:"@,"(binding_opctxt))ands(expressionctxt)body|Pexp_extensione->extensionctxtfe|Pexp_unreachable->ppf"."|Pexp_overwrite(e1,e2)->(* Similar to the case of [Pexp_stack] *)ppf"@[<hov2>overwrite_@ %a@ with@ %a@]"(expression2reset_ctxt)e1(expression2reset_ctxt)e2|Pexp_quotee->ppf"@[<hov2><[%a]>@]"(expressionctxt)e|Pexp_splicee->ppf"@[$%a@]"(simple_exprctxt)e|Pexp_hole->ppf"_"|Pexp_borrowe->ppf"@[<hov2>borrow_@ %a@]"(expression2reset_ctxt)e|_->expression1ctxtfxandexpression1ctxtfx=ifx.pexp_attributes<>[]thenexpressionctxtfxelsematchx.pexp_descwith|Pexp_objectcs->ppf"%a"(class_structurectxt)cs|_->expression2ctxtfx(* used in [Pexp_apply] *)andexpression2ctxtfx=ifx.pexp_attributes<>[]thenexpressionctxtfxelsematchx.pexp_descwith|Pexp_field(e,li)->ppf"@[<hov2>%a.%a@]"(simple_exprctxt)elongident_locli|Pexp_unboxed_field(e,li)->ppf"@[<hov2>%a.#%a@]"(simple_exprctxt)elongident_locli|Pexp_send(e,s)->ppf"@[<hov2>%a#%a@]"(simple_exprctxt)eident_of_names.txt|_->simple_exprctxtfxandsimple_exprctxtfx=ifx.pexp_attributes<>[]thenexpressionctxtfxelsematchx.pexp_descwith|Pexp_construct_whenis_simple_construct(view_exprx)->(matchview_exprxwith|`nil->ppf"[]"|`tuple->ppf"()"|`btrue->ppf"true"|`bfalse->ppf"false"|`listxs->ppf"@[<hv0>[%a]@]"(list(expression(under_semictxt))~sep:";@;")xs|`simplex->longidentfx|_->assertfalse)|Pexp_identli->longident_locfli(* (match view_fixity_of_exp x with *)(* |`Normal -> longident_loc f li *)(* | `Prefix _ | `Infix _ -> pp f "( %a )" longident_loc li) *)|Pexp_constantc->constantfc;|Pexp_packme->ppf"(module@;%a)"(module_exprctxt)me|Pexp_unboxed_unit->ppf"#()"|Pexp_unboxed_boolb->ppf"#%a"boolb|Pexp_tuplel->labeled_tuple_exprctxtf~unboxed:falsel|Pexp_unboxed_tuplel->labeled_tuple_exprctxtf~unboxed:truel|Pexp_constraint(e,ct,m)->beginmatchctwith|None->ppf"(%a : %@ %a)"(expressionctxt)emodesm|Somect->ppf"(%a : %a)"(expressionctxt)e(core_type2_with_optional_modesctxt)(ct,m)end|Pexp_coerce(e,cto1,ct)->ppf"(%a%a :> %a)"(expressionctxt)e(option(core_typectxt)~first:" : "~last:" ")cto1(* no sep hint*)(core_typectxt)ct|Pexp_variant(l,None)->ppf"`%a"ident_of_namel|Pexp_record(l,eo)->record_exprctxtf~unboxed:falseleo|Pexp_record_unboxed_product(l,eo)->record_exprctxtf~unboxed:trueleo|Pexp_array(mut,l)->letpunct=matchmutwith|Immutable->':'|Mutable->'|'inppf"@[<0>@[<2>[%c%a%c]@]@]"punct(list(simple_expr(under_semictxt))~sep:";")lpunct|Pexp_idx(ba,uas)->ppf"(%a%a)"(block_accessctxt)ba(listunboxed_access~sep:"")uas|Pexp_comprehensioncomp->comprehension_exprctxtfcomp|Pexp_while(e1,e2)->letfmt:(_,_,_)format="@[<2>while@;%a@;do@;%a@;done@]"inppffmt(expressionctxt)e1(expressionctxt)e2|Pexp_for(s,e1,e2,df,e3)->letfmt:(_,_,_)format="@[<hv0>@[<hv2>@[<2>for %a =@;%a@;%a%a@;do@]@;%a@]@;done@]"inletexpression=expressionctxtinppffmt(patternctxt)sexpressione1direction_flagdfexpressione2expressione3|Pexp_hole->ppf"_"|_->parentrue(expressionctxt)fxandattributesctxtfl=List.iter(attributectxtf)landitem_attributesctxtfl=List.iter(item_attributectxtf)landattributectxtfa=ppf"@[<2>[@@%s@ %a]@]"a.attr_name.txt(payloadctxt)a.attr_payloadanditem_attributectxtfa=ppf"@[<2>[@@@@%s@ %a]@]"a.attr_name.txt(payloadctxt)a.attr_payloadandfloating_attributectxtfa=ppf"@[<2>[@@@@@@%s@ %a]@]"a.attr_name.txt(payloadctxt)a.attr_payloadandvalue_descriptionctxtfx=(* note: value_description has an attribute field,
but they're already printed by the callers this method *)ppf"@[<hov2>%a%a%a@]"(core_typectxt)x.pval_typeoptional_space_atat_modalitiesx.pval_modalities(funfx->ifx.pval_prim<>[]thenppf"@ =@ %a"(listconstant_string)x.pval_prim)xandextensionctxtf(s,e)=ppf"@[<2>[%%%s@ %a]@]"s.txt(payloadctxt)eanditem_extensionctxtf(s,e)=ppf"@[<2>[%%%%%s@ %a]@]"s.txt(payloadctxt)eandexception_declarationctxtfx=ppf"@[<hov2>exception@ %a@]%a"(extension_constructorctxt)x.ptyexn_constructor(item_attributesctxt)x.ptyexn_attributesandclass_type_fieldctxtfx=matchx.pctf_descwith|Pctf_inherit(ct)->ppf"@[<2>inherit@ %a@]%a"(class_typectxt)ct(item_attributesctxt)x.pctf_attributes|Pctf_val(s,mf,vf,ct)->ppf"@[<2>val @ %a%a%a@ :@ %a@]%a"mutable_flagmfvirtual_flagvfident_of_names.txt(core_typectxt)ct(item_attributesctxt)x.pctf_attributes|Pctf_method(s,pf,vf,ct)->ppf"@[<2>method %a %a%a :@;%a@]%a"private_flagpfvirtual_flagvfident_of_names.txt(core_typectxt)ct(item_attributesctxt)x.pctf_attributes|Pctf_constraint(ct1,ct2)->ppf"@[<2>constraint@ %a@ =@ %a@]%a"(core_typectxt)ct1(core_typectxt)ct2(item_attributesctxt)x.pctf_attributes|Pctf_attributea->floating_attributectxtfa|Pctf_extensione->item_extensionctxtfe;item_attributesctxtfx.pctf_attributesandclass_signaturectxtf{pcsig_self=ct;pcsig_fields=l;_}=ppf"@[<hv0>@[<hv2>object@[<1>%a@]@ %a@]@ end@]"(funf->function{ptyp_desc=Ptyp_anyNone;ptyp_attributes=[];_}->()|ct->ppf" (%a)"(core_typectxt)ct)ct(list(class_type_fieldctxt)~sep:"@;")l(* call [class_signature] called by [class_signature] *)andclass_typectxtfx=matchx.pcty_descwith|Pcty_signaturecs->class_signaturectxtfcs;attributesctxtfx.pcty_attributes|Pcty_constr(li,l)->ppf"%a%a%a"(funfl->matchlwith|[]->()|_->ppf"[%a]@ "(list(core_typectxt)~sep:",")l)llongident_locli(attributesctxt)x.pcty_attributes|Pcty_arrow(l,co,cl)->ppf"@[<2>%a@;->@;%a@]"(* FIXME remove parens later *)(type_with_labelctxt)(l,co,[])(class_typectxt)cl|Pcty_extensione->extensionctxtfe;attributesctxtfx.pcty_attributes|Pcty_open(o,e)->ppf"@[<2>let open%s %a in@;%a@]"(overrideo.popen_override)longident_loco.popen_expr(class_typectxt)e(* [class type a = object end] *)andclass_type_declaration_listctxtfl=letclass_type_declarationkwdfx=let{pci_params=ls;pci_name={txt;_};_}=xinppf"@[<2>%s %a%a%a@ =@ %a@]%a"kwdvirtual_flagx.pci_virtclass_params_deflsident_of_nametxt(class_typectxt)x.pci_expr(item_attributesctxt)x.pci_attributesinmatchlwith|[]->()|[x]->class_type_declaration"class type"fx|x::xs->ppf"@[<v>%a@,%a@]"(class_type_declaration"class type")x(list~sep:"@,"(class_type_declaration"and"))xsandclass_fieldctxtfx=matchx.pcf_descwith|Pcf_inherit(ovf,ce,so)->ppf"@[<2>inherit@ %s@ %a%a@]%a"(overrideovf)(class_exprctxt)ce(funfso->matchsowith|None->();|Some(s)->ppf"@ as %a"ident_of_names.txt)so(item_attributesctxt)x.pcf_attributes|Pcf_val(s,mf,Cfk_concrete(ovf,e))->ppf"@[<2>val%s %a%a =@;%a@]%a"(overrideovf)mutable_flagmfident_of_names.txt(expressionctxt)e(item_attributesctxt)x.pcf_attributes|Pcf_method(s,pf,Cfk_virtualct)->ppf"@[<2>method virtual %a %a :@;%a@]%a"private_flagpfident_of_names.txt(core_typectxt)ct(item_attributesctxt)x.pcf_attributes|Pcf_val(s,mf,Cfk_virtualct)->ppf"@[<2>val virtual %a%a :@ %a@]%a"mutable_flagmfident_of_names.txt(core_typectxt)ct(item_attributesctxt)x.pcf_attributes|Pcf_method(s,pf,Cfk_concrete(ovf,e))->letbinde=bindingctxtf{pvb_pat={ppat_desc=Ppat_vars;ppat_loc=Location.none;ppat_loc_stack=[];ppat_attributes=[]};pvb_expr=e;pvb_constraint=None;pvb_is_poly=false;pvb_attributes=[];pvb_modes=[];pvb_loc=Location.none;}inppf"@[<2>method%s %a%a@]%a"(overrideovf)private_flagpf(funf->function|{pexp_desc=Pexp_poly(e,Somect);pexp_attributes=[];_}->ppf"%a :@;%a=@;%a"ident_of_names.txt(core_typectxt)ct(expressionctxt)e|{pexp_desc=Pexp_poly(e,None);pexp_attributes=[];_}->binde|_->binde)e(item_attributesctxt)x.pcf_attributes|Pcf_constraint(ct1,ct2)->ppf"@[<2>constraint %a =@;%a@]%a"(core_typectxt)ct1(core_typectxt)ct2(item_attributesctxt)x.pcf_attributes|Pcf_initializer(e)->ppf"@[<2>initializer@ %a@]%a"(expressionctxt)e(item_attributesctxt)x.pcf_attributes|Pcf_attributea->floating_attributectxtfa|Pcf_extensione->item_extensionctxtfe;item_attributesctxtfx.pcf_attributesandclass_structurectxtf{pcstr_self=p;pcstr_fields=l}=ppf"@[<hv0>@[<hv2>object%a@;%a@]@;end@]"(funfp->matchp.ppat_descwith|Ppat_any->()|Ppat_constraint_->ppf" %a"(patternctxt)p|_->ppf" (%a)"(patternctxt)p)p(list(class_fieldctxt))landclass_exprctxtfx=ifx.pcl_attributes<>[]thenbeginppf"((%a)%a)"(class_exprctxt){xwithpcl_attributes=[]}(attributesctxt)x.pcl_attributesendelsematchx.pcl_descwith|Pcl_structure(cs)->class_structurectxtfcs|Pcl_fun(l,eo,p,e)->ppf"fun@ %a@ ->@ %a"(label_expctxt)(l,eo,p)(class_exprctxt)e|Pcl_let(rf,l,ce)->ppf"%a@ in@ %a"(bindingsctxt)(Immutable,rf,l)(class_exprctxt)ce|Pcl_apply(ce,l)->ppf"((%a)@ %a)"(* Cf: #7200 *)(class_exprctxt)ce(list(label_x_expression_paramctxt))l|Pcl_constr(li,l)->ppf"%a%a"(funfl->ifl<>[]thenppf"[%a]@ "(list(core_typectxt)~sep:",")l)llongident_locli|Pcl_constraint(ce,ct)->ppf"(%a@ :@ %a)"(class_exprctxt)ce(class_typectxt)ct|Pcl_extensione->extensionctxtfe|Pcl_open(o,e)->ppf"@[<2>let open%s %a in@;%a@]"(overrideo.popen_override)longident_loco.popen_expr(class_exprctxt)eandinclude_:'a.ctxt->formatter->contents:(ctxt->formatter->'a->unit)->'ainclude_infos->unit=functxtf~contentsincl->ppf"@[<hov2>include%a@ %a@]%a"include_kindincl.pincl_kind(contentsctxt)incl.pincl_mod(item_attributesctxt)incl.pincl_attributesandsig_includectxtfinclmoda=include_ctxtf~contents:module_typeincl;optional_space_atat_modalitiesfmodaandjkind_declarationctxtfjd=beginmatchjd.pjkind_manifestwith|None->()|Somejkind->ppf"@;%a"(jkind_annotationctxt)jkindendandjkind_defctxtfjd=leteq=ifjd.pjkind_manifest=Nonethen""else" ="inppf"@[<2>kind_@ %a%s%a@]%a"string_locjd.pjkind_nameeq(jkind_declarationctxt)jd(item_attributesctxt)jd.pjkind_attributesandmodule_type_with_optional_modesctxtf(mty,mm)=matchmmwith|[]->module_typectxtfmty|_::_->ppf"%a%a"(module_type1ctxt)mtyoptional_at_modesmmandmodule_type1_with_optional_modesctxtf(mty,mm)=matchmmwith|[]->module_type1ctxtfmty|_::_->ppf"%a%a"(module_type1ctxt)mtyoptional_at_modesmmandmodule_typectxtfx=ifx.pmty_attributes<>[]thenbeginppf"((%a)%a)"(module_typectxt){xwithpmty_attributes=[]}(attributesctxt)x.pmty_attributesendelsematchx.pmty_descwith|Pmty_functor(Unit,mt2,mm2)->ppf"@[<hov2>() ->@ %a@]"(module_type_with_optional_modesctxt)(mt2,mm2)|Pmty_functor(Named(s,mt1,mm1),mt2,mm2)->beginmatchs.txtwith|None->ppf"@[<hov2>%a@ ->@ %a@]"(module_type1_with_optional_modesctxt)(mt1,mm1)(module_type_with_optional_modesctxt)(mt2,mm2)|Somename->ppf"@[<hov2>functor@ (%s@ :@ %a)@ ->@ %a@]"name(module_type_with_optional_modesctxt)(mt1,mm1)(module_type_with_optional_modesctxt)(mt2,mm2)end|Pmty_with(mt,[])->module_typectxtfmt|Pmty_with(mt,l)->ppf"@[<hov2>%a@ with@ %a@]"(module_type1ctxt)mt(list(with_constraintctxt)~sep:"@ and@ ")l|Pmty_strengthen(mty,mod_id)->ppf"@[<hov2>%a@ with@ %a@]"(module_type1ctxt)mtylongident_locmod_id|_->module_type1ctxtfxandwith_constraintctxtf=function|Pwith_type(li,({ptype_params=ls;_}astd))->ppf"type@ %a %a =@ %a"type_paramslslongident_locli(type_declarationctxt)td|Pwith_module(li,li2)->ppf"module %a =@ %a"longident_loclilongident_locli2;|Pwith_modtype(li,mty)->ppf"module type %a =@ %a"longident_locli(module_typectxt)mty;|Pwith_jkind(li,jd)->ppf"kind_ %a =@ %a"longident_locli(jkind_declarationctxt)jd;|Pwith_typesubst(li,({ptype_params=ls;_}astd))->ppf"type@ %a %a :=@ %a"type_paramslslongident_locli(type_declarationctxt)td|Pwith_modsubst(li,li2)->ppf"module %a :=@ %a"longident_loclilongident_locli2|Pwith_modtypesubst(li,mty)->ppf"module type %a :=@ %a"longident_locli(module_typectxt)mty;|Pwith_jkindsubst(li,jd)->ppf"kind_ %a :=@ %a"longident_locli(jkind_declarationctxt)jd;andmodule_type1ctxtfx=ifx.pmty_attributes<>[]thenmodule_typectxtfxelsematchx.pmty_descwith|Pmty_identli->ppf"%a"longident_locli;|Pmty_aliasli->ppf"(module %a)"longident_locli;|Pmty_signature{psg_items;psg_modalities}->ppf"@[<hv0>@[<hv2>sig%a@ %a@]@ end@]"(* "@[<hov>sig@ %a@ end@]" *)optional_space_atat_modalitiespsg_modalities(list(signature_itemctxt))psg_items(* FIXME wrong indentation*)|Pmty_typeofme->ppf"@[<hov2>module@ type@ of@ %a@]"(module_exprctxt)me|Pmty_extensione->extensionctxtfe|_->parentrue(module_typectxt)fxandsignaturectxtf{psg_items;psg_modalities}=optional_atat_modalities_newlinefpsg_modalities;signature_itemsctxtfpsg_itemsandsignature_itemsctxtfitems=list~sep:"@\n"(signature_itemctxt)fitemsandsignature_itemctxtfx:unit=matchx.psig_descwith|Psig_type(rf,l)->type_def_listctxtf(rf,true,l)|Psig_typesubstl->(* Psig_typesubst is never recursive, but we specify [Recursive] here to
avoid printing a [nonrec] flag, which would be rejected by the parser.
*)type_def_listctxtf(Recursive,false,l)|Psig_valuevd->letintro=ifvd.pval_prim=[]then"val"else"external"inifvd.pval_prim<>[]thenassert(notvd.pval_poly);letpoly_str=ifvd.pval_polythen"poly_ "else""inppf"@[<2>%s@ %s%a@ :@ %a@]%a"intropoly_strident_of_namevd.pval_name.txt(value_descriptionctxt)vd(item_attributesctxt)vd.pval_attributes|Psig_typextte->type_extensionctxtfte|Psig_exceptioned->exception_declarationctxtfed|Psig_classl->letclass_descriptionkwdf({pci_params=ls;pci_name={txt;_};_}asx)=ppf"@[<2>%s %a%a%a@;:@;%a@]%a"kwdvirtual_flagx.pci_virtclass_params_deflsident_of_nametxt(class_typectxt)x.pci_expr(item_attributesctxt)x.pci_attributesinbeginmatchlwith|[]->()|[x]->class_description"class"fx|x::xs->ppf"@[<v>%a@,%a@]"(class_description"class")x(list~sep:"@,"(class_description"and"))xsend|Psig_module({pmd_type={pmty_desc=Pmty_aliasalias;pmty_attributes=[];_};_}aspmd)->ppf"@[<hov>module@ %s@ =@ %a%a@]%a"(Option.valuepmd.pmd_name.txt~default:"_")longident_localiasoptional_space_atat_modalitiespmd.pmd_modalities(item_attributesctxt)pmd.pmd_attributes|Psig_modulepmd->ppf"@[<hov>module@ %s@ :@ %a%a@]%a"(Option.valuepmd.pmd_name.txt~default:"_")(module_typectxt)pmd.pmd_typeoptional_space_atat_modalitiespmd.pmd_modalities(item_attributesctxt)pmd.pmd_attributes|Psig_modsubstpms->ppf"@[<hov>module@ %s@ :=@ %a@]%a"pms.pms_name.txtlongident_locpms.pms_manifest(item_attributesctxt)pms.pms_attributes|Psig_openod->ppf"@[<hov2>open%s@ %a@]%a"(overrideod.popen_override)longident_locod.popen_expr(item_attributesctxt)od.popen_attributes|Psig_include(incl,modalities)->sig_includectxtfinclmodalities|Psig_modtype{pmtd_name=s;pmtd_type=md;pmtd_attributes=attrs}->ppf"@[<hov2>module@ type@ %s%a@]%a"s.txt(funfmd->matchmdwith|None->()|Somemt->pp_print_spacef();ppf"@ =@ %a"(module_typectxt)mt)md(item_attributesctxt)attrs|Psig_modtypesubst{pmtd_name=s;pmtd_type=md;pmtd_attributes=attrs}->letmd=matchmdwith|None->assertfalse(* ast invariant *)|Somemt->mtinppf"@[<hov2>module@ type@ %s@ :=@ %a@]%a"s.txt(module_typectxt)md(item_attributesctxt)attrs|Psig_class_type(l)->class_type_declaration_listctxtfl|Psig_recmoduledecls->letrecstring_x_module_type_listf?(first=true)l=matchlwith|[]->();|pmd::tl->ifnotfirstthenppf"@ @[<hov2>and@ %s:@ %a%a@]%a"(Option.valuepmd.pmd_name.txt~default:"_")(module_type1ctxt)pmd.pmd_typeoptional_space_atat_modalitiespmd.pmd_modalities(item_attributesctxt)pmd.pmd_attributeselseppf"@[<hov2>module@ rec@ %s:@ %a%a@]%a"(Option.valuepmd.pmd_name.txt~default:"_")(module_type1ctxt)pmd.pmd_typeoptional_space_atat_modalitiespmd.pmd_modalities(item_attributesctxt)pmd.pmd_attributes;string_x_module_type_listf~first:falsetlinstring_x_module_type_listfdecls|Psig_attributea->floating_attributectxtfa|Psig_extension(e,a)->item_extensionctxtfe;item_attributesctxtfa|Psig_jkindkd->jkind_defctxtfkdandmodule_exprctxtfx=ifx.pmod_attributes<>[]thenppf"((%a)%a)"(module_exprctxt){xwithpmod_attributes=[]}(attributesctxt)x.pmod_attributeselsematchx.pmod_descwith|Pmod_structure(s)->ppf"@[<hv2>struct@;@[<0>%a@]@;<1 -2>end@]"(list(structure_itemctxt)~sep:"@\n")s;|Pmod_constraint(me,mt,mm)->beginmatchmtwith|None->ppf"@[<hov2>(%a%a)@]"(module_exprctxt)meoptional_at_modesmm|Somemt->ppf"@[<hov2>(%a@ :@ %a)@]"(module_exprctxt)me(module_type_with_optional_modesctxt)(mt,mm)end|Pmod_ident(li)->ppf"%a"longident_locli;|Pmod_functor(Unit,me)->ppf"functor ()@;->@;%a"(module_exprctxt)me|Pmod_functor(Named(s,mt,mm),me)->ppf"functor@ (%s@ :@ %a)@;->@;%a"(Option.values.txt~default:"_")(module_type_with_optional_modesctxt)(mt,mm)(module_exprctxt)me|Pmod_apply(me1,me2)->ppf"(%a)(%a)"(module_exprctxt)me1(module_exprctxt)me2(* Cf: #7200 *)|Pmod_apply_unitme1->ppf"(%a)()"(module_exprctxt)me1|Pmod_unpacke->ppf"(val@ %a)"(expressionctxt)e|Pmod_extension({txt;_},_)whentxt=Ast_helper.hole_txt->ppf"_"|Pmod_extensione->extensionctxtfe|Pmod_instancei->ppf"(%a [@jane.non_erasable.instances])"(instancectxt)iandstructurectxtfx=list~sep:"@\n"(structure_itemctxt)fxandpayloadctxtf=function|PStr[{pstr_desc=Pstr_eval(e,attrs)}]->ppf"@[<2>%a@]%a"(expressionctxt)e(item_attributesctxt)attrs|PStrx->structurectxtfx|PTypx->ppf":@ ";core_typectxtfx|PSigx->ppf":@ ";signaturectxtfx|PPat(x,None)->ppf"?";patternctxtfx|PPat(x,Somee)->ppf"?@ ";patternctxtfx;ppf" when ";expressionctxtfeandpp_print_pexp_newtypectxtsepfx=(* We go to some trouble to print nested [Pexp_newtype] as
newtype parameters of the same "fun" (rather than printing several nested
"fun (type a) -> ..."). This isn't necessary for round-tripping -- it just
makes the pretty-printing a bit prettier. *)ifx.pexp_attributes<>[]thenppf"%s@;%a"sep(expressionctxt)xelsematchx.pexp_descwith|Pexp_newtype(str,jkind,e)->ppf"(type@ %a)@ %a"name_jkind(str.txt,jkind)(pp_print_pexp_newtypectxtsep)e|_->ppf"%s@;%a"sep(expressionctxt)xandpp_print_params_then_equalsctxtfx=ifx.pexp_attributes<>[]thenppf"=@;%a"(expressionctxt)xelsematchx.pexp_descwith|Pexp_function(params,constraint_,body)->function_params_then_bodyctxtfparamsconstraint_body~delimiter:Equals|_->pp_print_pexp_newtypectxt"="fxandpoly_typectxtcore_typef(vars,typ)=ppf"type@;%a.@;%a"(list~sep:"@;"(tyvar_loc_jkindpp_print_string))vars(core_typectxt)typandpoly_type_with_optional_modesctxtf(vars,typ,modes)=matchmodeswith|[]->poly_typectxtcore_typef(vars,typ)|_::_->ppf"%a%a"(poly_typectxtcore_type1)(vars,typ)optional_at_modesmodes(* transform [f = fun g h -> ..] to [f g h = ... ] could be improved *)andbindingctxtf{pvb_pat=p;pvb_expr=x;pvb_constraint=ct;pvb_modes=modes;_}=(* .pvb_attributes have already been printed by the caller, #bindings *)matchctwith|Some(Pvc_constraint{locally_abstract_univars=[];typ})->ppf"%a@;:@;%a@;=@;%a"(simple_patternctxt)p(core_type2_with_optional_modesctxt)(typ,modes)(expressionctxt)x|Some(Pvc_constraint{locally_abstract_univars=vars;typ})->ppf"%a@;: %a@;=@;%a"(simple_patternctxt)p(poly_type_with_optional_modesctxt)(List.map(funx->(x,None))vars,typ,modes)(expressionctxt)x|Some(Pvc_coercion{ground=None;coercion})->ppf"%a@;:>@;%a@;=@;%a"(simple_patternctxt)p(core_typectxt)coercion(expressionctxt)x|Some(Pvc_coercion{ground=Someground;coercion})->ppf"%a@;:%a@;:>@;%a@;=@;%a"(simple_patternctxt)p(core_typectxt)ground(core_typectxt)coercion(expressionctxt)x|None->(* CR layouts 1.5: We just need to check for [is_desugared_gadt] because
the parser hasn't been upgraded to parse [let x : type a. ... = ...] as
[Pvb_constraint] as it has been upstream. Once we move to the 5.2
parsetree encoding of type annotations.
*)lettyvars_strtyvars=List.map(funv->v.txt)tyvarsinlettyvars_jkind_strtyvars=List.map(fun(v,_jkind)->v.txt)tyvarsinletis_desugared_gadtpe=letgadt_pattern=matchpwith|{ppat_desc=Ppat_constraint({ppat_desc=Ppat_var_}aspat,Some{ptyp_desc=Ptyp_poly(args_tyvars,rt)},_);ppat_attributes=[]}->Some(pat,args_tyvars,rt)|_->Noneinletrecgadt_exptyvarse=matchewith(* no need to handle jkind annotations here; the extracted variables
don't get printed -- they're just used to decide how to print *)|{pexp_desc=Pexp_newtype(tyvar,_jkind,e);pexp_attributes=[]}->gadt_exp(tyvar::tyvars)e|{pexp_desc=Pexp_constraint(e,Somect,_);pexp_attributes=[]}->Some(List.revtyvars,e,ct)|_->Noneinletgadt_exp=gadt_exp[]einmatchgadt_pattern,gadt_expwith|Some(p,pt_tyvars,pt_ct),Some(e_tyvars,e,e_ct)whentyvars_jkind_strpt_tyvars=tyvars_stre_tyvars->letety=Ast_helper.Typ.varify_constructorse_tyvarse_ctinifety=pt_ctthenSome(p,pt_tyvars,e_ct,e)elseNone|_->Noneinbeginmatchis_desugared_gadtpxwith|Some(p,(_::_astyvars),ct,e)->ppf"%a@;: %a@;=@;%a"(simple_patternctxt)p(poly_type_with_optional_modesctxt)(tyvars,ct,modes)(expressionctxt)e|_->beginmatchpwith|{ppat_desc=Ppat_var_;ppat_attributes=[]}->beginmatchmodeswith|[]->ppf"%a@ %a"(simple_patternctxt)p(pp_print_params_then_equalsctxt)x|_->ppf"(%a%a)@ %a"(simple_patternctxt)poptional_at_modesmodes(pp_print_params_then_equalsctxt)xend|_->ppf"%a%a@;=@;%a"(patternctxt)poptional_at_modesmodes(expressionctxt)xendend(* [in] is not printed *)andbindingsctxtf(mf,rf,l)=letbindingkwdmfrffx=(* The other modes are printed inside [binding] *)letpoly_str=ifx.pvb_is_polythen"poly_ "else""inppf"@[<2>%s %a%s%a%a@]%a"kwdmutable_flagmfpoly_strrec_flagrf(bindingctxt)x(item_attributesctxt)x.pvb_attributesinmatchlwith|[]->()|[x]->binding"let"mfrffx|x::xs->ppf"@[<v>%a@,%a@]"(binding"let"mfrf)x(list~sep:"@,"(binding"and"ImmutableNonrecursive))xsandbinding_opctxtfx=matchx.pbop_pat,x.pbop_expwith|{ppat_desc=Ppat_var{txt=pvar;_};ppat_attributes=[];_},{pexp_desc=Pexp_ident{txt=Lidentevar;_};pexp_attributes=[];_}whenpvar=evar->ppf"@[<2>%s %s@]"x.pbop_op.txtevar|pat,exp->ppf"@[<2>%s %a@;=@;%a@]"x.pbop_op.txt(patternctxt)pat(expressionctxt)expandstructure_itemctxtfx=matchx.pstr_descwith|Pstr_eval(e,attrs)->ppf"@[<hov2>;;%a@]%a"(expressionctxt)e(item_attributesctxt)attrs|Pstr_type(_,[])->assertfalse|Pstr_type(rf,l)->type_def_listctxtf(rf,true,l)|Pstr_value(rf,l)->(* pp f "@[<hov2>let %a%a@]" rec_flag rf bindings l *)ppf"@[<2>%a@]"(bindingsctxt)(Immutable,rf,l)|Pstr_typextte->type_extensionctxtfte|Pstr_exceptioned->exception_declarationctxtfed|Pstr_modulex->letrecmodule_helper=function|{pmod_desc=Pmod_functor(arg_opt,me');pmod_attributes=[]}->beginmatcharg_optwith|Unit->ppf"()"|Named(s,mt,mm)->ppf"(%s:%a)"(Option.values.txt~default:"_")(module_type_with_optional_modesctxt)(mt,mm)end;module_helperme'|me->meinppf"@[<hov2>module %s%a@]%a"(Option.valuex.pmb_name.txt~default:"_")(funfme->letme=module_helpermeinmatchmewith|{pmod_desc=Pmod_constraint(me',Some({pmty_desc=(Pmty_ident(_)|Pmty_signature(_));_}asmt),mm);pmod_attributes=[]}->ppf" :@;%a@;=@;%a@;"(module_type_with_optional_modesctxt)(mt,mm)(module_exprctxt)me'|_->ppf" =@ %a"(module_exprctxt)me)x.pmb_expr(item_attributesctxt)x.pmb_attributes|Pstr_openod->ppf"@[<2>open%s@;%a@]%a"(overrideod.popen_override)(module_exprctxt)od.popen_expr(item_attributesctxt)od.popen_attributes|Pstr_modtype{pmtd_name=s;pmtd_type=md;pmtd_attributes=attrs}->ppf"@[<hov2>module@ type@ %s%a@]%a"s.txt(funfmd->matchmdwith|None->()|Somemt->pp_print_spacef();ppf"@ =@ %a"(module_typectxt)mt)md(item_attributesctxt)attrs|Pstr_classl->letextract_class_argscl=letrecloopacc=function|{pcl_desc=Pcl_fun(l,eo,p,cl');pcl_attributes=[]}->loop((l,eo,p)::acc)cl'|cl->List.revacc,clinletargs,cl=loop[]clinletconstr,cl=matchclwith|{pcl_desc=Pcl_constraint(cl',ct);pcl_attributes=[]}->Somect,cl'|_->None,clinargs,constr,clinletclass_constraintfct=ppf": @[%a@] "(class_typectxt)ctinletclass_declarationkwdf({pci_params=ls;pci_name={txt;_};_}asx)=letargs,constr,cl=extract_class_argsx.pci_exprinppf"@[<2>%s %a%a%a %a%a=@;%a@]%a"kwdvirtual_flagx.pci_virtclass_params_deflsident_of_nametxt(list(label_expctxt)~last:"@ ")args(optionclass_constraint)constr(class_exprctxt)cl(item_attributesctxt)x.pci_attributesinbeginmatchlwith|[]->()|[x]->class_declaration"class"fx|x::xs->ppf"@[<v>%a@,%a@]"(class_declaration"class")x(list~sep:"@,"(class_declaration"and"))xsend|Pstr_class_typel->class_type_declaration_listctxtfl|Pstr_primitivevd->assert(notvd.pval_poly);ppf"@[<hov2>external@ %a@ :@ %a@]%a"ident_of_namevd.pval_name.txt(value_descriptionctxt)vd(item_attributesctxt)vd.pval_attributes|Pstr_includeincl->include_ctxtf~contents:module_exprincl|Pstr_recmoduledecls->(* 3.07 *)letauxf=function|({pmb_expr={pmod_desc=Pmod_constraint(expr,Sometyp,mm)}}aspmb)->ppf"@[<hov2>@ and@ %s:%a@ =@ %a@]%a"(Option.valuepmb.pmb_name.txt~default:"_")(module_type_with_optional_modesctxt)(typ,mm)(module_exprctxt)expr(item_attributesctxt)pmb.pmb_attributes|({pmb_expr={pmod_desc=Pmod_constraint(expr,None,mm)}}aspmb)->ppf"@[<hov2>@ and@ %s%a@ =@ %a@]%a"(Option.valuepmb.pmb_name.txt~default:"_")optional_at_modesmm(module_exprctxt)expr(item_attributesctxt)pmb.pmb_attributes|pmb->ppf"@[<hov2>@ and@ %s@ =@ %a@]%a"(Option.valuepmb.pmb_name.txt~default:"_")(module_exprctxt)pmb.pmb_expr(item_attributesctxt)pmb.pmb_attributesinbeginmatchdeclswith|({pmb_expr={pmod_desc=Pmod_constraint(expr,Sometyp,mm)}}aspmb)::l2->ppf"@[<hv>@[<hov2>module@ rec@ %s:%a@ =@ %a@]%a@ %a@]"(Option.valuepmb.pmb_name.txt~default:"_")(module_type_with_optional_modesctxt)(typ,mm)(module_exprctxt)expr(item_attributesctxt)pmb.pmb_attributes(funfl2->List.iter(auxf)l2)l2|({pmb_expr={pmod_desc=Pmod_constraint(expr,None,mm)}}aspmb)::l2->ppf"@[<hv>@[<hov2>module@ rec@ %s%a@ =@ %a@]%a@ %a@]"(Option.valuepmb.pmb_name.txt~default:"_")optional_at_modesmm(module_exprctxt)expr(item_attributesctxt)pmb.pmb_attributes(funfl2->List.iter(auxf)l2)l2|pmb::l2->ppf"@[<hv>@[<hov2>module@ rec@ %s@ =@ %a@]%a@ %a@]"(Option.valuepmb.pmb_name.txt~default:"_")(module_exprctxt)pmb.pmb_expr(item_attributesctxt)pmb.pmb_attributes(funfl2->List.iter(auxf)l2)l2|_->assertfalseend|Pstr_attributea->floating_attributectxtfa|Pstr_extension(e,a)->item_extensionctxtfe;item_attributesctxtfa|Pstr_jkindjd->jkind_defctxtfjd(* Don't just use [core_type] because we do not want parens around params
with jkind annotations *)andcore_type_paramfct=letattrs=attributesreset_ctxtinmatchct.ptyp_descwith|Ptyp_anyNone->ppf"_%a"attrsct.ptyp_attributes|Ptyp_any(Somejk)->ppf"_%a : %a"attrsct.ptyp_attributes(jkind_annotationreset_ctxt)jk|Ptyp_var(s,None)->ppf"%a%a"tyvarsattrsct.ptyp_attributes|Ptyp_var(s,Somejk)->ppf"%a%a : %a"tyvarsattrsct.ptyp_attributes(jkind_annotationreset_ctxt)jk|_->Misc.fatal_error"unexpected type in core_type_param"andtype_paramf(ct,(a,b))=ppf"%s%s%a"(type_variancea)(type_injectivityb)core_type_paramctandtype_paramsf=function|[]->()(* Normally, one param doesn't get parentheses, but it does when there is
a jkind annotation. *)|[{ptyp_desc=Ptyp_any(Some_)|Ptyp_var(_,Some_)},_asparam]->ppf"(%a) "type_paramparam|l->ppf"%a "(listtype_param~first:"("~last:")"~sep:",@;")landtype_def_listctxtf(rf,exported,l)=lettype_declkwdrffx=leteq=if(x.ptype_kind=Ptype_abstract)&&(x.ptype_manifest=None)then""elseifexportedthen" ="else" :="inletlayout_annot=matchx.ptype_jkind_annotationwith|None->Format.dprintf""|Somejkind->Format.dprintf" : %a"(jkind_annotationctxt)jkindinppf"@[<2>%s %a%a%a%t%s%a@]%a"kwdnonrec_flagrftype_paramsx.ptype_paramsident_of_namex.ptype_name.txtlayout_annoteq(type_declarationctxt)x(item_attributesctxt)x.ptype_attributesinmatchlwith|[]->assertfalse|[x]->type_decl"type"rffx|x::xs->ppf"@[<v>%a@,%a@]"(type_decl"type"rf)x(list~sep:"@,"(type_decl"and"Recursive))xsandrecord_declarationctxtf~unboxedlbls=lettype_record_fieldfpld=ppf"@[<2>%a%a:@;%a%a@;%a@]"mutable_flagpld.pld_mutableident_of_namepld.pld_name.txt(core_typectxt)pld.pld_typeoptional_space_atat_modalitiespld.pld_modalities(attributesctxt)pld.pld_attributesinlethash=ifunboxedthen"#"else""inppf"%s{@\n%a}"hash(listtype_record_field~sep:";@\n")lblsandtype_declarationctxtfx=(* type_declaration has an attribute field,
but it's been printed by the caller of this method *)letprivf=matchx.ptype_privatewith|Public->()|Private->ppf"@;private"inletmanifestf=matchx.ptype_manifestwith|None->()|Somey->ifx.ptype_kind=Ptype_abstractthenppf"%t@;%a"priv(core_typectxt)yelseppf"@;%a"(core_typectxt)yinletconstructor_declarationfpcd=ppf"|@;";constructor_declarationctxtf(pcd.pcd_name.txt,pcd.pcd_vars,pcd.pcd_args,pcd.pcd_res,pcd.pcd_attributes)inletreprf=letintrof=ifx.ptype_manifest=Nonethen()elseppf"@;="inmatchx.ptype_kindwith|Ptype_variantxs->letvariantsfmtxs=ifxs=[]thenppfmt" |"elseppfmt"@\n%a"(list~sep:"@\n"constructor_declaration)xsinppf"%t%t%a"introprivvariantsxs|Ptype_abstract->()|Ptype_recordl->ppf"%t%t@;%a"intropriv(record_declarationctxt~unboxed:false)l|Ptype_record_unboxed_productl->ppf"%t%t@;%a"intropriv(record_declarationctxt~unboxed:true)l|Ptype_open->ppf"%t%t@;.."introprivinletconstraintsf=List.iter(fun(ct1,ct2,_)->ppf"@[<hov2>@ constraint@ %a@ =@ %a@]"(core_typectxt)ct1(core_typectxt)ct2)x.ptype_cstrsinppf"%t%t%t"manifestreprconstraintsandtype_extensionctxtfx=letextension_constructorfx=ppf"@\n|@;%a"(extension_constructorctxt)xinppf"@[<2>type %a%a += %a@ %a@]%a"type_paramsx.ptyext_paramslongident_locx.ptyext_pathprivate_flagx.ptyext_private(* Cf: #7200 *)(list~sep:""extension_constructor)x.ptyext_constructors(item_attributesctxt)x.ptyext_attributesandconstructor_declarationctxtf(name,vars_jkinds,args,res,attrs)=letname=matchnamewith|"::"->"(::)"|s->sinletpp_varsfvls=matchvlswith|[]->()|_->ppf"%a@;.@;"(list(tyvar_loc_jkindtyvar)~sep:"@;")vlsinmatchreswith|None->ppf"%s%a@;%a"name(funf->function|Pcstr_tuple[]->()|Pcstr_tuplel->ppf"@;of@;%a"(list(modalities_typecore_type1ctxt)~sep:"@;*@;")l|Pcstr_recordl->ppf"@;of@;%a"(record_declarationctxt~unboxed:false)l)args(attributesctxt)attrs|Somer->ppf"%s:@;%a%a@;%a"namepp_varsvars_jkinds(funf->function|Pcstr_tuple[]->core_type1ctxtfr|Pcstr_tuplel->ppf"%a@;->@;%a"(list(modalities_typecore_type1ctxt)~sep:"@;*@;")l(core_type1ctxt)r|Pcstr_recordl->ppf"%a@;->@;%a"(record_declarationctxt~unboxed:false)l(core_type1ctxt)r)args(attributesctxt)attrsandextension_constructorctxtfx=(* Cf: #7200 *)matchx.pext_kindwith|Pext_decl(v,l,r)->constructor_declarationctxtf(x.pext_name.txt,v,l,r,x.pext_attributes)|Pext_rebindli->ppf"%s@;=@;%a%a"x.pext_name.txtlongident_locli(attributesctxt)x.pext_attributesandcase_listctxtfl:unit=letauxf{pc_lhs;pc_guard;pc_rhs}=ppf"@;| @[<2>%a%a@;->@;%a@]"(patternctxt)pc_lhs(option(expressionctxt)~first:"@;when@;")pc_guard(expression(under_pipectxt))pc_rhsinlistauxfl~sep:""andlabel_x_expression_paramctxtf(l,e)=letsimple_name=matchewith|{pexp_desc=Pexp_ident{txt=Lidentl;_};pexp_attributes=[]}->Somel|_->Noneinmatchlwith|Nolabel->expression2ctxtfe(* level 2*)|Optionalstr->ifSomestr=simple_namethenppf"?%a"ident_of_namestrelseppf"?%a:%a"ident_of_namestr(simple_exprctxt)e|Labelledlbl->ifSomelbl=simple_namethenppf"~%a"ident_of_namelblelseppf"~%a:%a"ident_of_namelbl(simple_exprctxt)eandtuple_componentctxtf(l,e)=letsimple_name=matchewith|{pexp_desc=Pexp_ident{txt=Lidentl;_};pexp_attributes=[]}->Somel|_->Noneinmatch(simple_name,l)with(* Labeled component can be represented with pun *)|Somesimple_name,SomelblwhenString.equalsimple_namelbl->ppf"~%s"lbl(* Labeled component general case *)|_,Somelbl->ppf"~%s:%a"lbl(simple_exprctxt)e(* Unlabeled component *)|_,None->expression2ctxtfe(* level 2*)anddirective_argumentfx=matchx.pdira_descwith|Pdir_string(s)->ppf"@ %S"s|Pdir_int(n,None)->ppf"@ %s"n|Pdir_int(n,Somem)->ppf"@ %s%c"nm|Pdir_ident(li)->ppf"@ %a"longidentli|Pdir_bool(b)->ppf"@ %s"(string_of_boolb)andblock_accessctxtf=function|Baccess_fieldli->ppf".%a"longident_locli|Baccess_block(mut,index)->lets=matchmutwith|Mutable->"idx_mut"|Immutable->"idx_imm"inppf".%s(%a)"s(expressionctxt)indexandunboxed_accessf=function|Uaccess_unboxed_fieldli->ppf".#%a"longident_locliandcomprehension_exprctxtfcexp=letpunct,comp=matchcexpwith|Pcomp_list_comprehensioncomp->"",comp|Pcomp_array_comprehension(amut,comp)->letpunct=matchamutwith|Mutable->"|"|Immutable->":"inpunct,compincomprehensionctxtf~open_:("["^punct)~close:(punct^"]")compandcomprehensionctxtf~open_~closecexp=let{pcomp_body=body;pcomp_clauses=clauses}=cexpinppf"@[<hv0>@[<hv2>%s%a@ @[<hv2>%a@]%s@]@]"open_(expressionctxt)body(list~sep:"@ "(comprehension_clausectxt))clausescloseandcomprehension_clausectxtfx=matchxwith|Pcomp_forbindings->ppf"@[for %a@]"(list~sep:"@]@ @[and "(comprehension_bindingctxt))bindings|Pcomp_whencond->ppf"@[when %a@]"(expressionctxt)condandcomprehension_bindingctxtfx=let{pcomp_cb_pattern=pat;pcomp_cb_iterator=iterator;pcomp_cb_attributes=attrs}=xinppf"%a%a %a"(attributesctxt)attrs(patternctxt)pat(comprehension_iteratorctxt)iteratorandcomprehension_iteratorctxtfx=matchxwith|Pcomp_range{start;stop;direction}->ppf"=@ %a %a%a"(expressionctxt)startdirection_flagdirection(expressionctxt)stop|Pcomp_inseq->ppf"in %a"(expressionctxt)seqandfunction_paramctxtf{pparam_desc;pparam_loc=_}=matchpparam_descwith|Pparam_val(a,b,c)->label_expctxtf(a,b,c)|Pparam_newtype(ty,None)->ppf"(type %a)"ident_of_namety.txt|Pparam_newtype(ty,Someannot)->ppf"(type %a : %a)"ident_of_namety.txt(jkind_annotationctxt)annotandfunction_bodyctxtfx=matchxwith|Pfunction_bodybody->expressionctxtfbody|Pfunction_cases(cases,_,attrs)->ppf"@[<hv>function%a%a@]"(item_attributesctxt)attrs(case_listctxt)casesandfunction_constraint~followed_by_arrowctxtfx=(* We don't print [mode_annotations], which describes the whole function and
goes on the [let] binding. *)(* Enable warning 9 to ensure that the record pattern doesn't miss any field.
*)match[@ocaml.warning"+9"]xwith|{ret_type_constraint=Some(Pconstraintty);ret_mode_annotations;_}->(* We need extra parens around the type if the next character is an arrow,
to avoid printing [fun x : int -> int -> x] *)letprint_ty=iffollowed_by_arrowthencore_type1_with_optional_modescore_type1ctxtelsecore_type2_with_optional_modesctxtinppf"@;:@;%a@;"print_ty(ty,ret_mode_annotations)|{ret_type_constraint=Some(Pcoerce(ty1,ty2));_}->ppf"@;%a:>@;%a"(option~first:":@;"(core_typectxt))ty1(core_typectxt)ty2|{ret_type_constraint=None;ret_mode_annotations;_}->ppf"%a"optional_at_modesret_mode_annotationsandfunction_params_then_bodyctxtfparamsconstraint_body~delimiter=letfollowed_by_arrow,delimiter=matchdelimiterwith|Arrow->true,"->"|Equals->false,"="inletpp_paramsf=matchparamswith|[]->()|_::_->ppf"%a@;"(list(function_paramctxt)~sep:"@ ")paramsinppf"%t%a%s@;%a"pp_params(function_constraint~followed_by_arrowctxt)constraint_delimiter(function_body(under_functionrhsctxt))bodyandlabeled_tuple_exprctxtf~unboxedx=ppf"@[<hov2>%s(%a)@]"(ifunboxedthen"#"else"")(list(tuple_componentctxt)~sep:",@;")xandrecord_exprctxtf~unboxedleo=letlongident_x_expressionf(li,e)=matchewith|{pexp_desc=Pexp_ident{txt;_};pexp_attributes=[];_}whenli.txt=txt->ppf"@[<hov2>%a@]"longident_locli|_->ppf"@[<hov2>%a@;=@;%a@]"longident_locli(simple_exprctxt)einlethash=ifunboxedthen"#"else""inppf"@[<hv0>@[<hv2>%s{@;%a%a@]@;}@]"(* "@[<hov2>%s{%a%a}@]" *)hash(option~last:" with@;"(simple_exprctxt))eo(listlongident_x_expression~sep:";@;")landinstancectxtfx=matchxwith|{pmod_instance_head=head;pmod_instance_args=[]}->ppf"%s"head|{pmod_instance_head=head;pmod_instance_args=args}->ppf"@[<2>%s %a@]"head(list(instance_argctxt))argsandinstance_argctxtf(param,value)=ppf"@[<1>(%s)@;(%a)@]"param(instancectxt)value(******************************************************************************)(* All exported functions must be defined or redefined below here and wrapped in
[export_printer] in order to ensure they are invariant with respecto which
language extensions are enabled. *)letLanguage_extension.For_pprintast.{print_with_maximal_extensions}=Language_extension.For_pprintast.make_printer_exporter()letprint_reset_with_maximal_extensionsf=print_with_maximal_extensions(freset_ctxt)lettoplevel_phrasefx=matchxwith|Ptop_def(s)->ppf"@[<hov0>%a@]"(list(structure_itemreset_ctxt))s(* pp_open_hvbox f 0; *)(* pp_print_list structure_item f s ; *)(* pp_close_box f (); *)|Ptop_dir{pdir_name;pdir_arg=None;_}->ppf"@[<hov2>#%s@]"pdir_name.txt|Ptop_dir{pdir_name;pdir_arg=Somepdir_arg;_}->ppf"@[<hov2>#%s@ %a@]"pdir_name.txtdirective_argumentpdir_arglettoplevel_phrase=print_with_maximal_extensionstoplevel_phraseletexpressionfx=ppf"@[%a@]"(expressionreset_ctxt)xletexpression=print_with_maximal_extensionsexpressionletstring_of_expressionx=ignore(flush_str_formatter());letf=str_formatterinexpressionfx;flush_str_formatter()letstructure=print_reset_with_maximal_extensionsstructureletstring_of_structurex=ignore(flush_str_formatter());letf=str_formatterinstructurefx;flush_str_formatter()lettop_phrasefx=pp_print_newlinef();toplevel_phrasefx;ppf";;";pp_print_newlinef()letlongident=print_with_maximal_extensionslongidentletcore_type=print_reset_with_maximal_extensionscore_typeletpattern=print_reset_with_maximal_extensionspatternletsignature=print_reset_with_maximal_extensionssignatureletmodule_expr=print_reset_with_maximal_extensionsmodule_exprletmodule_type=print_reset_with_maximal_extensionsmodule_typeletclass_field=print_reset_with_maximal_extensionsclass_fieldletclass_type_field=print_reset_with_maximal_extensionsclass_type_fieldletclass_expr=print_reset_with_maximal_extensionsclass_exprletclass_type=print_reset_with_maximal_extensionsclass_typeletclass_signature=print_reset_with_maximal_extensionsclass_signatureletstructure_item=print_reset_with_maximal_extensionsstructure_itemletsignature_item=print_reset_with_maximal_extensionssignature_itemletsignature_items=print_reset_with_maximal_extensionssignature_itemsletbinding=print_reset_with_maximal_extensionsbindingletpayload=print_reset_with_maximal_extensionspayloadlettype_declaration=print_reset_with_maximal_extensionstype_declarationletjkind_annotation=print_reset_with_maximal_extensionsjkind_annotationmoduleDoc=structincludeDoc_internalletjkind_annotationppfjkind=Format_doc.deprecated_printer(funfmt->jkind_annotationfmtjkind)ppfend(* Added in merlin *)letcase_list=print_reset_with_maximal_extensionscase_listmoduleStyle=Misc.Style(* This comes from upstream's [parsing/parse.ml] *)letprepare_errorerr=letsource=Location.ParserinletopenSyntaxerrinmatcherrwith|Unclosed(opening_loc,opening,closing_loc,closing)->Location.errorf~source~loc:closing_loc~sub:[Location.msg~loc:opening_loc"This %a might be unmatched"Style.inline_codeopening]"Syntax error: %a expected"Style.inline_codeclosing|Expecting(loc,nonterm)->Location.errorf~source~loc"Syntax error: %a expected."Style.inline_codenonterm|Not_expecting(loc,nonterm)->Location.errorf~source~loc"Syntax error: %a not expected."Style.inline_codenonterm|Applicative_pathloc->Location.errorf~source~loc"Syntax error: applicative paths of the form %a \
are not supported when the option %a is set."Style.inline_code"F(X).t"Style.inline_code"-no-app-func"|Variable_in_scope(loc,var)->Location.errorf~source~loc"In this scoped type, variable %a \
is reserved for the local type %a."(Style.as_inline_codeDoc.tyvar)varStyle.inline_codevar|Otherloc->Location.errorf~source~loc"Syntax error"|Ill_formed_ast(loc,s)->Location.errorf~source~loc"broken invariant in parsetree: %s"s|Invalid_package_type(loc,ipt)->letinvalidppfipt=matchiptwith|Syntaxerr.Parameterized_types->Format_doc.fprintfppf"parametrized types are not supported"|Constrained_types->Format_doc.fprintfppf"constrained types are not supported"|Private_types->Format_doc.fprintfppf"private types are not supported"|Not_with_type->Format_doc.fprintfppf"only %a constraints are supported"Style.inline_code"with type t ="|Neither_identifier_nor_with_type->Format_doc.fprintfppf"only module type identifier and %a constraints are supported"Style.inline_code"with type"|Misplaced_attribute->Format_doc.fprintfppf"an attribute cannot go here"inLocation.errorf~loc"invalid package type: %a"invalidipt|Removed_string_setloc->Location.errorf~source~loc"Syntax error: strings are immutable, there is no assignment \
syntax for them.\n\
@{<hint>Hint@}: Mutable sequences of bytes are available in \
the Bytes module.\n\
@{<hint>Hint@}: Did you mean to use %a?"Style.inline_code"Bytes.set"|Missing_unboxed_literal_suffixloc->Location.errorf~source~loc"Syntax error: Unboxed integer literals require width suffixes."|Malformed_instance_identifierloc->Location.errorf~source~loc"Syntax error: Unexpected in module instance"|Quotation_reserved(loc,symb)->Location.errorf~source~loc"Syntax error: `%s` is reserved for use in runtime metaprogramming."symb|Unspliceableloc->Location.errorf~loc"Syntax error: expression cannot be spliced.\n\
@{<hint>Hint@}: consider putting parentheses around the \
expression."|Let_mutable_not_allowed_at_structure_levelloc->Location.errorf~source~loc"Syntax error: Mutable let bindings are not allowed \
at the structure level."|Let_mutable_not_allowed_in_class_definitionloc->Location.errorf~source~loc"Syntax error: Mutable let bindings are not allowed \
inside class definitions."|Let_mutable_not_allowed_with_function_bindingsloc->Location.errorf~source~loc"Syntax error: Mutable let is not allowed with function bindings.\n\
@{<hint>Hint@}: If you really want a mutable function variable, \
use the de-sugared syntax:\n %a"Style.inline_code"let mutable f = fun x -> .."|Block_access_bad_parenloc->Location.errorf~source~loc"Syntax error: A parenthesis here can only follow one of: \n \
%a, %a, %a, %a, %a, %a, %a, %a, %a, %a."Style.inline_code"."Style.inline_code".L"Style.inline_code".l"Style.inline_code".n"Style.inline_code".:"Style.inline_code".:L"Style.inline_code".:l"Style.inline_code".:n"Style.inline_code".idx_imm"Style.inline_code".idx_mut"let()=Location.register_error_of_exn(function|Syntaxerr.Errorerr->Some(prepare_errorerr)|_->None)