12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083(**************************************************************************)(* *)(* OCaml Migrate Parsetree *)(* *)(* Frédéric Bour *)(* Jérémie Dimino and Leo White, Jane Street Europe *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* Alain Frisch, LexiFi *)(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 2017 Institut National de Recherche en Informatique et *)(* en Automatique (INRIA). *)(* *)(* 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. *)(* *)(**************************************************************************)(* Ast ported on Mon Oct 2 11:25:57 CEST 2017
OCaml trunk was:
commit 65940a2c6be43c42f75c6c6b255974f7e6de03ca (HEAD -> 4.06, origin/4.06)
Author: Christophe Raffalli <christophe@raffalli.eu>
Date: Sun Oct 1 18:27:07 2017 +0200
fixed position of last optional last semicolumn in sequence (#1387)
*)moduleLocation=LocationmoduleLongident=LongidentmoduleAsttypes=struct(** Auxiliary AST types used by parsetree and typedtree. *)typeconstant(*IF_CURRENT = Asttypes.constant *)=Const_intofint|Const_charofchar|Const_stringofstring*stringoption|Const_floatofstring|Const_int32ofint32|Const_int64ofint64|Const_nativeintofnativeinttyperec_flag(*IF_CURRENT = Asttypes.rec_flag *)=Nonrecursive|Recursivetypedirection_flag(*IF_CURRENT = Asttypes.direction_flag *)=Upto|Downto(* Order matters, used in polymorphic comparison *)typeprivate_flag(*IF_CURRENT = Asttypes.private_flag *)=Private|Publictypemutable_flag(*IF_CURRENT = Asttypes.mutable_flag *)=Immutable|Mutabletypevirtual_flag(*IF_CURRENT = Asttypes.virtual_flag *)=Virtual|Concretetypeoverride_flag(*IF_CURRENT = Asttypes.override_flag *)=Override|Freshtypeclosed_flag(*IF_CURRENT = Asttypes.closed_flag *)=Closed|Opentypelabel=stringtypearg_label(*IF_CURRENT = Asttypes.arg_label *)=Nolabel|Labelledofstring(* label:T -> ... *)|Optionalofstring(* ?label:T -> ... *)type'aloc='aLocation.loc={txt:'a;loc:Location.t;}typevariance(*IF_CURRENT = Asttypes.variance *)=|Covariant|Contravariant|InvariantendmoduleParsetree=struct(** Abstract syntax tree produced by parsing *)openAsttypestypeconstant(*IF_CURRENT = Parsetree.constant *)=Pconst_integerofstring*charoption(* 3 3l 3L 3n
Suffixes [g-z][G-Z] are accepted by the parser.
Suffixes except 'l', 'L' and 'n' are rejected by the typechecker
*)|Pconst_charofchar(* 'c' *)|Pconst_stringofstring*stringoption(* "constant"
{delim|other constant|delim}
*)|Pconst_floatofstring*charoption(* 3.4 2e5 1.4e-4
Suffixes [g-z][G-Z] are accepted by the parser.
Suffixes are rejected by the typechecker.
*)(** {2 Extension points} *)typeattribute=stringloc*payload(* [@id ARG]
[@@id ARG]
Metadata containers passed around within the AST.
The compiler ignores unknown attributes.
*)andextension=stringloc*payload(* [%id ARG]
[%%id ARG]
Sub-language placeholder -- rejected by the typechecker.
*)andattributes=attributelistandpayload(*IF_CURRENT = Parsetree.payload *)=|PStrofstructure|PSigofsignature(* : SIG *)|PTypofcore_type(* : T *)|PPatofpattern*expressionoption(* ? P or ? P when E *)(** {2 Core language} *)(* Type expressions *)andcore_type(*IF_CURRENT = Parsetree.core_type *)={ptyp_desc:core_type_desc;ptyp_loc:Location.t;ptyp_attributes:attributes;(* ... [@id1] [@id2] *)}andcore_type_desc(*IF_CURRENT = Parsetree.core_type_desc *)=|Ptyp_any(* _ *)|Ptyp_varofstring(* 'a *)|Ptyp_arrowofarg_label*core_type*core_type(* T1 -> T2 Simple
~l:T1 -> T2 Labelled
?l:T1 -> T2 Optional
*)|Ptyp_tupleofcore_typelist(* T1 * ... * Tn
Invariant: n >= 2
*)|Ptyp_constrofLongident.tloc*core_typelist(* tconstr
T tconstr
(T1, ..., Tn) tconstr
*)|Ptyp_objectofobject_fieldlist*closed_flag(* < l1:T1; ...; ln:Tn > (flag = Closed)
< l1:T1; ...; ln:Tn; .. > (flag = Open)
*)|Ptyp_classofLongident.tloc*core_typelist(* #tconstr
T #tconstr
(T1, ..., Tn) #tconstr
*)|Ptyp_aliasofcore_type*string(* T as 'a *)|Ptyp_variantofrow_fieldlist*closed_flag*labellistoption(* [ `A|`B ] (flag = Closed; labels = None)
[> `A|`B ] (flag = Open; labels = None)
[< `A|`B ] (flag = Closed; labels = Some [])
[< `A|`B > `X `Y ](flag = Closed; labels = Some ["X";"Y"])
*)|Ptyp_polyofstringloclist*core_type(* 'a1 ... 'an. T
Can only appear in the following context:
- As the core_type of a Ppat_constraint node corresponding
to a constraint on a let-binding: let x : 'a1 ... 'an. T
= e ...
- Under Cfk_virtual for methods (not values).
- As the core_type of a Pctf_method node.
- As the core_type of a Pexp_poly node.
- As the pld_type field of a label_declaration.
- As a core_type of a Ptyp_object node.
*)|Ptyp_packageofpackage_type(* (module S) *)|Ptyp_extensionofextension(* [%id] *)andpackage_type=Longident.tloc*(Longident.tloc*core_type)list(*
(module S)
(module S with type t1 = T1 and ... and tn = Tn)
*)androw_field(*IF_CURRENT = Parsetree.row_field *)=|Rtagoflabelloc*attributes*bool*core_typelist(* [`A] ( true, [] )
[`A of T] ( false, [T] )
[`A of T1 & .. & Tn] ( false, [T1;...Tn] )
[`A of & T1 & .. & Tn] ( true, [T1;...Tn] )
- The 2nd field is true if the tag contains a
constant (empty) constructor.
- '&' occurs when several types are used for the same constructor
(see 4.2 in the manual)
- TODO: switch to a record representation, and keep location
*)|Rinheritofcore_type(* [ T ] *)andobject_field(*IF_CURRENT = Parsetree.object_field *)=|Otagoflabelloc*attributes*core_type|Oinheritofcore_type(* Patterns *)andpattern(*IF_CURRENT = Parsetree.pattern *)={ppat_desc:pattern_desc;ppat_loc:Location.t;ppat_attributes:attributes;(* ... [@id1] [@id2] *)}andpattern_desc(*IF_CURRENT = Parsetree.pattern_desc *)=|Ppat_any(* _ *)|Ppat_varofstringloc(* x *)|Ppat_aliasofpattern*stringloc(* P as 'a *)|Ppat_constantofconstant(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)|Ppat_intervalofconstant*constant(* 'a'..'z'
Other forms of interval are recognized by the parser
but rejected by the type-checker. *)|Ppat_tupleofpatternlist(* (P1, ..., Pn)
Invariant: n >= 2
*)|Ppat_constructofLongident.tloc*patternoption(* C None
C P Some P
C (P1, ..., Pn) Some (Ppat_tuple [P1; ...; Pn])
*)|Ppat_variantoflabel*patternoption(* `A (None)
`A P (Some P)
*)|Ppat_recordof(Longident.tloc*pattern)list*closed_flag(* { l1=P1; ...; ln=Pn } (flag = Closed)
{ l1=P1; ...; ln=Pn; _} (flag = Open)
Invariant: n > 0
*)|Ppat_arrayofpatternlist(* [| P1; ...; Pn |] *)|Ppat_orofpattern*pattern(* P1 | P2 *)|Ppat_constraintofpattern*core_type(* (P : T) *)|Ppat_typeofLongident.tloc(* #tconst *)|Ppat_lazyofpattern(* lazy P *)|Ppat_unpackofstringloc(* (module P)
Note: (module P : S) is represented as
Ppat_constraint(Ppat_unpack, Ptyp_package)
*)|Ppat_exceptionofpattern(* exception P *)|Ppat_extensionofextension(* [%id] *)|Ppat_openofLongident.tloc*pattern(* M.(P) *)(* Value expressions *)andexpression(*IF_CURRENT = Parsetree.expression *)={pexp_desc:expression_desc;pexp_loc:Location.t;pexp_attributes:attributes;(* ... [@id1] [@id2] *)}andexpression_desc(*IF_CURRENT = Parsetree.expression_desc *)=|Pexp_identofLongident.tloc(* x
M.x
*)|Pexp_constantofconstant(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)|Pexp_letofrec_flag*value_bindinglist*expression(* let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
*)|Pexp_functionofcaselist(* function P1 -> E1 | ... | Pn -> En *)|Pexp_funofarg_label*expressionoption*pattern*expression(* fun P -> E1 (Simple, None)
fun ~l:P -> E1 (Labelled l, None)
fun ?l:P -> E1 (Optional l, None)
fun ?l:(P = E0) -> E1 (Optional l, Some E0)
Notes:
- If E0 is provided, only Optional is allowed.
- "fun P1 P2 .. Pn -> E1" is represented as nested Pexp_fun.
- "let f P = E" is represented using Pexp_fun.
*)|Pexp_applyofexpression*(arg_label*expression)list(* E0 ~l1:E1 ... ~ln:En
li can be empty (non labeled argument) or start with '?'
(optional argument).
Invariant: n > 0
*)|Pexp_matchofexpression*caselist(* match E0 with P1 -> E1 | ... | Pn -> En *)|Pexp_tryofexpression*caselist(* try E0 with P1 -> E1 | ... | Pn -> En *)|Pexp_tupleofexpressionlist(* (E1, ..., En)
Invariant: n >= 2
*)|Pexp_constructofLongident.tloc*expressionoption(* C None
C E Some E
C (E1, ..., En) Some (Pexp_tuple[E1;...;En])
*)|Pexp_variantoflabel*expressionoption(* `A (None)
`A E (Some E)
*)|Pexp_recordof(Longident.tloc*expression)list*expressionoption(* { l1=P1; ...; ln=Pn } (None)
{ E0 with l1=P1; ...; ln=Pn } (Some E0)
Invariant: n > 0
*)|Pexp_fieldofexpression*Longident.tloc(* E.l *)|Pexp_setfieldofexpression*Longident.tloc*expression(* E1.l <- E2 *)|Pexp_arrayofexpressionlist(* [| E1; ...; En |] *)|Pexp_ifthenelseofexpression*expression*expressionoption(* if E1 then E2 else E3 *)|Pexp_sequenceofexpression*expression(* E1; E2 *)|Pexp_whileofexpression*expression(* while E1 do E2 done *)|Pexp_forofpattern*expression*expression*direction_flag*expression(* for i = E1 to E2 do E3 done (flag = Upto)
for i = E1 downto E2 do E3 done (flag = Downto)
*)|Pexp_constraintofexpression*core_type(* (E : T) *)|Pexp_coerceofexpression*core_typeoption*core_type(* (E :> T) (None, T)
(E : T0 :> T) (Some T0, T)
*)|Pexp_sendofexpression*labelloc(* E # m *)|Pexp_newofLongident.tloc(* new M.c *)|Pexp_setinstvaroflabelloc*expression(* x <- 2 *)|Pexp_overrideof(labelloc*expression)list(* {< x1 = E1; ...; Xn = En >} *)|Pexp_letmoduleofstringloc*module_expr*expression(* let module M = ME in E *)|Pexp_letexceptionofextension_constructor*expression(* let exception C in E *)|Pexp_assertofexpression(* assert E
Note: "assert false" is treated in a special way by the
type-checker. *)|Pexp_lazyofexpression(* lazy E *)|Pexp_polyofexpression*core_typeoption(* Used for method bodies.
Can only be used as the expression under Cfk_concrete
for methods (not values). *)|Pexp_objectofclass_structure(* object ... end *)|Pexp_newtypeofstringloc*expression(* fun (type t) -> E *)|Pexp_packofmodule_expr(* (module ME)
(module ME : S) is represented as
Pexp_constraint(Pexp_pack, Ptyp_package S) *)|Pexp_openofoverride_flag*Longident.tloc*expression(* M.(E)
let open M in E
let! open M in E *)|Pexp_extensionofextension(* [%id] *)|Pexp_unreachable(* . *)andcase(*IF_CURRENT = Parsetree.case *)=(* (P -> E) or (P when E0 -> E) *){pc_lhs:pattern;pc_guard:expressionoption;pc_rhs:expression;}(* Value descriptions *)andvalue_description(*IF_CURRENT = Parsetree.value_description *)={pval_name:stringloc;pval_type:core_type;pval_prim:stringlist;pval_attributes:attributes;(* ... [@@id1] [@@id2] *)pval_loc:Location.t;}(*
val x: T (prim = [])
external x: T = "s1" ... "sn" (prim = ["s1";..."sn"])
*)(* Type declarations *)andtype_declaration(*IF_CURRENT = Parsetree.type_declaration *)={ptype_name:stringloc;ptype_params:(core_type*variance)list;(* ('a1,...'an) t; None represents _*)ptype_cstrs:(core_type*core_type*Location.t)list;(* ... constraint T1=T1' ... constraint Tn=Tn' *)ptype_kind:type_kind;ptype_private:private_flag;(* = private ... *)ptype_manifest:core_typeoption;(* = T *)ptype_attributes:attributes;(* ... [@@id1] [@@id2] *)ptype_loc:Location.t;}(*
type t (abstract, no manifest)
type t = T0 (abstract, manifest=T0)
type t = C of T | ... (variant, no manifest)
type t = T0 = C of T | ... (variant, manifest=T0)
type t = {l: T; ...} (record, no manifest)
type t = T0 = {l : T; ...} (record, manifest=T0)
type t = .. (open, no manifest)
*)andtype_kind(*IF_CURRENT = Parsetree.type_kind *)=|Ptype_abstract|Ptype_variantofconstructor_declarationlist(* Invariant: non-empty list *)|Ptype_recordoflabel_declarationlist(* Invariant: non-empty list *)|Ptype_openandlabel_declaration(*IF_CURRENT = Parsetree.label_declaration *)={pld_name:stringloc;pld_mutable:mutable_flag;pld_type:core_type;pld_loc:Location.t;pld_attributes:attributes;(* l : T [@id1] [@id2] *)}(* { ...; l: T; ... } (mutable=Immutable)
{ ...; mutable l: T; ... } (mutable=Mutable)
Note: T can be a Ptyp_poly.
*)andconstructor_declaration(*IF_CURRENT = Parsetree.constructor_declaration *)={pcd_name:stringloc;pcd_args:constructor_arguments;pcd_res:core_typeoption;pcd_loc:Location.t;pcd_attributes:attributes;(* C of ... [@id1] [@id2] *)}andconstructor_arguments(*IF_CURRENT = Parsetree.constructor_arguments *)=|Pcstr_tupleofcore_typelist|Pcstr_recordoflabel_declarationlist(*
| C of T1 * ... * Tn (res = None, args = Pcstr_tuple [])
| C: T0 (res = Some T0, args = [])
| C: T1 * ... * Tn -> T0 (res = Some T0, args = Pcstr_tuple)
| C of {...} (res = None, args = Pcstr_record)
| C: {...} -> T0 (res = Some T0, args = Pcstr_record)
| C of {...} as t (res = None, args = Pcstr_record)
*)andtype_extension(*IF_CURRENT = Parsetree.type_extension *)={ptyext_path:Longident.tloc;ptyext_params:(core_type*variance)list;ptyext_constructors:extension_constructorlist;ptyext_private:private_flag;ptyext_attributes:attributes;(* ... [@@id1] [@@id2] *)}(*
type t += ...
*)andextension_constructor(*IF_CURRENT = Parsetree.extension_constructor *)={pext_name:stringloc;pext_kind:extension_constructor_kind;pext_loc:Location.t;pext_attributes:attributes;(* C of ... [@id1] [@id2] *)}andextension_constructor_kind(*IF_CURRENT = Parsetree.extension_constructor_kind *)=Pext_declofconstructor_arguments*core_typeoption(*
| C of T1 * ... * Tn ([T1; ...; Tn], None)
| C: T0 ([], Some T0)
| C: T1 * ... * Tn -> T0 ([T1; ...; Tn], Some T0)
*)|Pext_rebindofLongident.tloc(*
| C = D
*)(** {2 Class language} *)(* Type expressions for the class language *)andclass_type(*IF_CURRENT = Parsetree.class_type *)={pcty_desc:class_type_desc;pcty_loc:Location.t;pcty_attributes:attributes;(* ... [@id1] [@id2] *)}andclass_type_desc(*IF_CURRENT = Parsetree.class_type_desc *)=|Pcty_constrofLongident.tloc*core_typelist(* c
['a1, ..., 'an] c *)|Pcty_signatureofclass_signature(* object ... end *)|Pcty_arrowofarg_label*core_type*class_type(* T -> CT Simple
~l:T -> CT Labelled l
?l:T -> CT Optional l
*)|Pcty_extensionofextension(* [%id] *)|Pcty_openofoverride_flag*Longident.tloc*class_type(* let open M in CT *)andclass_signature(*IF_CURRENT = Parsetree.class_signature *)={pcsig_self:core_type;pcsig_fields:class_type_fieldlist;}(* object('selfpat) ... end
object ... end (self = Ptyp_any)
*)andclass_type_field(*IF_CURRENT = Parsetree.class_type_field *)={pctf_desc:class_type_field_desc;pctf_loc:Location.t;pctf_attributes:attributes;(* ... [@@id1] [@@id2] *)}andclass_type_field_desc(*IF_CURRENT = Parsetree.class_type_field_desc *)=|Pctf_inheritofclass_type(* inherit CT *)|Pctf_valof(labelloc*mutable_flag*virtual_flag*core_type)(* val x: T *)|Pctf_methodof(labelloc*private_flag*virtual_flag*core_type)(* method x: T
Note: T can be a Ptyp_poly.
*)|Pctf_constraintof(core_type*core_type)(* constraint T1 = T2 *)|Pctf_attributeofattribute(* [@@@id] *)|Pctf_extensionofextension(* [%%id] *)and'aclass_infos(*IF_CURRENT = 'a Parsetree.class_infos *)={pci_virt:virtual_flag;pci_params:(core_type*variance)list;pci_name:stringloc;pci_expr:'a;pci_loc:Location.t;pci_attributes:attributes;(* ... [@@id1] [@@id2] *)}(* class c = ...
class ['a1,...,'an] c = ...
class virtual c = ...
Also used for "class type" declaration.
*)andclass_description=class_typeclass_infosandclass_type_declaration=class_typeclass_infos(* Value expressions for the class language *)andclass_expr(*IF_CURRENT = Parsetree.class_expr *)={pcl_desc:class_expr_desc;pcl_loc:Location.t;pcl_attributes:attributes;(* ... [@id1] [@id2] *)}andclass_expr_desc(*IF_CURRENT = Parsetree.class_expr_desc *)=|Pcl_constrofLongident.tloc*core_typelist(* c
['a1, ..., 'an] c *)|Pcl_structureofclass_structure(* object ... end *)|Pcl_funofarg_label*expressionoption*pattern*class_expr(* fun P -> CE (Simple, None)
fun ~l:P -> CE (Labelled l, None)
fun ?l:P -> CE (Optional l, None)
fun ?l:(P = E0) -> CE (Optional l, Some E0)
*)|Pcl_applyofclass_expr*(arg_label*expression)list(* CE ~l1:E1 ... ~ln:En
li can be empty (non labeled argument) or start with '?'
(optional argument).
Invariant: n > 0
*)|Pcl_letofrec_flag*value_bindinglist*class_expr(* let P1 = E1 and ... and Pn = EN in CE (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN in CE (flag = Recursive)
*)|Pcl_constraintofclass_expr*class_type(* (CE : CT) *)|Pcl_extensionofextension(* [%id] *)|Pcl_openofoverride_flag*Longident.tloc*class_expr(* let open M in CE *)andclass_structure(*IF_CURRENT = Parsetree.class_structure *)={pcstr_self:pattern;pcstr_fields:class_fieldlist;}(* object(selfpat) ... end
object ... end (self = Ppat_any)
*)andclass_field(*IF_CURRENT = Parsetree.class_field *)={pcf_desc:class_field_desc;pcf_loc:Location.t;pcf_attributes:attributes;(* ... [@@id1] [@@id2] *)}andclass_field_desc(*IF_CURRENT = Parsetree.class_field_desc *)=|Pcf_inheritofoverride_flag*class_expr*stringlocoption(* inherit CE
inherit CE as x
inherit! CE
inherit! CE as x
*)|Pcf_valof(labelloc*mutable_flag*class_field_kind)(* val x = E
val virtual x: T
*)|Pcf_methodof(labelloc*private_flag*class_field_kind)(* method x = E (E can be a Pexp_poly)
method virtual x: T (T can be a Ptyp_poly)
*)|Pcf_constraintof(core_type*core_type)(* constraint T1 = T2 *)|Pcf_initializerofexpression(* initializer E *)|Pcf_attributeofattribute(* [@@@id] *)|Pcf_extensionofextension(* [%%id] *)andclass_field_kind(*IF_CURRENT = Parsetree.class_field_kind *)=|Cfk_virtualofcore_type|Cfk_concreteofoverride_flag*expressionandclass_declaration=class_exprclass_infos(** {2 Module language} *)(* Type expressions for the module language *)andmodule_type(*IF_CURRENT = Parsetree.module_type *)={pmty_desc:module_type_desc;pmty_loc:Location.t;pmty_attributes:attributes;(* ... [@id1] [@id2] *)}andmodule_type_desc(*IF_CURRENT = Parsetree.module_type_desc *)=|Pmty_identofLongident.tloc(* S *)|Pmty_signatureofsignature(* sig ... end *)|Pmty_functorofstringloc*module_typeoption*module_type(* functor(X : MT1) -> MT2 *)|Pmty_withofmodule_type*with_constraintlist(* MT with ... *)|Pmty_typeofofmodule_expr(* module type of ME *)|Pmty_extensionofextension(* [%id] *)|Pmty_aliasofLongident.tloc(* (module M) *)andsignature=signature_itemlistandsignature_item(*IF_CURRENT = Parsetree.signature_item *)={psig_desc:signature_item_desc;psig_loc:Location.t;}andsignature_item_desc(*IF_CURRENT = Parsetree.signature_item_desc *)=|Psig_valueofvalue_description(*
val x: T
external x: T = "s1" ... "sn"
*)|Psig_typeofrec_flag*type_declarationlist(* type t1 = ... and ... and tn = ... *)|Psig_typextoftype_extension(* type t1 += ... *)|Psig_exceptionofextension_constructor(* exception C of T *)|Psig_moduleofmodule_declaration(* module X : MT *)|Psig_recmoduleofmodule_declarationlist(* module rec X1 : MT1 and ... and Xn : MTn *)|Psig_modtypeofmodule_type_declaration(* module type S = MT
module type S *)|Psig_openofopen_description(* open X *)|Psig_includeofinclude_description(* include MT *)|Psig_classofclass_descriptionlist(* class c1 : ... and ... and cn : ... *)|Psig_class_typeofclass_type_declarationlist(* class type ct1 = ... and ... and ctn = ... *)|Psig_attributeofattribute(* [@@@id] *)|Psig_extensionofextension*attributes(* [%%id] *)andmodule_declaration(*IF_CURRENT = Parsetree.module_declaration *)={pmd_name:stringloc;pmd_type:module_type;pmd_attributes:attributes;(* ... [@@id1] [@@id2] *)pmd_loc:Location.t;}(* S : MT *)andmodule_type_declaration(*IF_CURRENT = Parsetree.module_type_declaration *)={pmtd_name:stringloc;pmtd_type:module_typeoption;pmtd_attributes:attributes;(* ... [@@id1] [@@id2] *)pmtd_loc:Location.t;}(* S = MT
S (abstract module type declaration, pmtd_type = None)
*)andopen_description(*IF_CURRENT = Parsetree.open_description *)={popen_lid:Longident.tloc;popen_override:override_flag;popen_loc:Location.t;popen_attributes:attributes;}(* open! X - popen_override = Override (silences the 'used identifier
shadowing' warning)
open X - popen_override = Fresh
*)and'ainclude_infos(*IF_CURRENT = 'a Parsetree.include_infos *)={pincl_mod:'a;pincl_loc:Location.t;pincl_attributes:attributes;}andinclude_description=module_typeinclude_infos(* include MT *)andinclude_declaration=module_exprinclude_infos(* include ME *)andwith_constraint(*IF_CURRENT = Parsetree.with_constraint *)=|Pwith_typeofLongident.tloc*type_declaration(* with type X.t = ...
Note: the last component of the longident must match
the name of the type_declaration. *)|Pwith_moduleofLongident.tloc*Longident.tloc(* with module X.Y = Z *)|Pwith_typesubstofLongident.tloc*type_declaration(* with type X.t := ..., same format as [Pwith_type] *)|Pwith_modsubstofLongident.tloc*Longident.tloc(* with module X.Y := Z *)(* Value expressions for the module language *)andmodule_expr(*IF_CURRENT = Parsetree.module_expr *)={pmod_desc:module_expr_desc;pmod_loc:Location.t;pmod_attributes:attributes;(* ... [@id1] [@id2] *)}andmodule_expr_desc(*IF_CURRENT = Parsetree.module_expr_desc *)=|Pmod_identofLongident.tloc(* X *)|Pmod_structureofstructure(* struct ... end *)|Pmod_functorofstringloc*module_typeoption*module_expr(* functor(X : MT1) -> ME *)|Pmod_applyofmodule_expr*module_expr(* ME1(ME2) *)|Pmod_constraintofmodule_expr*module_type(* (ME : MT) *)|Pmod_unpackofexpression(* (val E) *)|Pmod_extensionofextension(* [%id] *)andstructure=structure_itemlistandstructure_item(*IF_CURRENT = Parsetree.structure_item *)={pstr_desc:structure_item_desc;pstr_loc:Location.t;}andstructure_item_desc(*IF_CURRENT = Parsetree.structure_item_desc *)=|Pstr_evalofexpression*attributes(* E *)|Pstr_valueofrec_flag*value_bindinglist(* let P1 = E1 and ... and Pn = EN (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN (flag = Recursive)
*)|Pstr_primitiveofvalue_description(* val x: T
external x: T = "s1" ... "sn" *)|Pstr_typeofrec_flag*type_declarationlist(* type t1 = ... and ... and tn = ... *)|Pstr_typextoftype_extension(* type t1 += ... *)|Pstr_exceptionofextension_constructor(* exception C of T
exception C = M.X *)|Pstr_moduleofmodule_binding(* module X = ME *)|Pstr_recmoduleofmodule_bindinglist(* module rec X1 = ME1 and ... and Xn = MEn *)|Pstr_modtypeofmodule_type_declaration(* module type S = MT *)|Pstr_openofopen_description(* open X *)|Pstr_classofclass_declarationlist(* class c1 = ... and ... and cn = ... *)|Pstr_class_typeofclass_type_declarationlist(* class type ct1 = ... and ... and ctn = ... *)|Pstr_includeofinclude_declaration(* include ME *)|Pstr_attributeofattribute(* [@@@id] *)|Pstr_extensionofextension*attributes(* [%%id] *)andvalue_binding(*IF_CURRENT = Parsetree.value_binding *)={pvb_pat:pattern;pvb_expr:expression;pvb_attributes:attributes;pvb_loc:Location.t;}andmodule_binding(*IF_CURRENT = Parsetree.module_binding *)={pmb_name:stringloc;pmb_expr:module_expr;pmb_attributes:attributes;pmb_loc:Location.t;}(* X = ME *)(** {2 Toplevel} *)(* Toplevel phrases *)typetoplevel_phrase(*IF_CURRENT = Parsetree.toplevel_phrase *)=|Ptop_defofstructure|Ptop_dirofstring*directive_argument(* #use, #load ... *)anddirective_argument(*IF_CURRENT = Parsetree.directive_argument *)=|Pdir_none|Pdir_stringofstring|Pdir_intofstring*charoption|Pdir_identofLongident.t|Pdir_boolofboolendmoduleDocstrings:sig(** {3 Docstrings} *)(** Documentation comments *)typedocstring(** Create a docstring *)valdocstring:string->Location.t->docstring(** Get the text of a docstring *)valdocstring_body:docstring->string(** Get the location of a docstring *)valdocstring_loc:docstring->Location.t(** {3 Items}
The {!docs} type represents documentation attached to an item. *)typedocs={docs_pre:docstringoption;docs_post:docstringoption;}valempty_docs:docsvaldocs_attr:docstring->Parsetree.attribute(** Convert item documentation to attributes and add them to an
attribute list *)valadd_docs_attrs:docs->Parsetree.attributes->Parsetree.attributes(** {3 Fields and constructors}
The {!info} type represents documentation attached to a field or
constructor. *)typeinfo=docstringoptionvalempty_info:infovalinfo_attr:docstring->Parsetree.attribute(** Convert field info to attributes and add them to an
attribute list *)valadd_info_attrs:info->Parsetree.attributes->Parsetree.attributes(** {3 Unattached comments}
The {!text} type represents documentation which is not attached to
anything. *)typetext=docstringlistvalempty_text:textvaltext_attr:docstring->Parsetree.attribute(** Convert text to attributes and add them to an attribute list *)valadd_text_attrs:text->Parsetree.attributes->Parsetree.attributesend=structopenLocation(* Docstrings *)typedocstring={ds_body:string;ds_loc:Location.t;}(* Docstring constructors and destructors *)letdocstringbodyloc=letds={ds_body=body;ds_loc=loc;}indsletdocstring_bodyds=ds.ds_bodyletdocstring_locds=ds.ds_loc(* Docstrings attached to items *)typedocs={docs_pre:docstringoption;docs_post:docstringoption;}letempty_docs={docs_pre=None;docs_post=None}letdoc_loc={txt="ocaml.doc";loc=Location.none}letdocs_attrds=letopenParsetreeinletexp={pexp_desc=Pexp_constant(Pconst_string(ds.ds_body,None));pexp_loc=ds.ds_loc;pexp_attributes=[];}inletitem={pstr_desc=Pstr_eval(exp,[]);pstr_loc=exp.pexp_loc}in(doc_loc,PStr[item])letadd_docs_attrsdocsattrs=letattrs=matchdocs.docs_prewith|None|Some{ds_body="";_}->attrs|Someds->docs_attrds::attrsinletattrs=matchdocs.docs_postwith|None|Some{ds_body="";_}->attrs|Someds->attrs@[docs_attrds]inattrs(* Docstrings attached to constructors or fields *)typeinfo=docstringoptionletempty_info=Noneletinfo_attr=docs_attrletadd_info_attrsinfoattrs=matchinfowith|None|Some{ds_body="";_}->attrs|Someds->attrs@[info_attrds](* Docstrings not attached to a specific item *)typetext=docstringlistletempty_text=[]lettext_loc={txt="ocaml.text";loc=Location.none}lettext_attrds=letopenParsetreeinletexp={pexp_desc=Pexp_constant(Pconst_string(ds.ds_body,None));pexp_loc=ds.ds_loc;pexp_attributes=[];}inletitem={pstr_desc=Pstr_eval(exp,[]);pstr_loc=exp.pexp_loc}in(text_loc,PStr[item])letadd_text_attrsdslattrs=letfdsl=List.filter(function{ds_body="";_}->false|_->true)dslin(List.maptext_attrfdsl)@attrsendmoduleAst_helper:sig(** Helpers to produce Parsetree fragments *)openAsttypesopenDocstringsopenParsetreetypelid=Longident.tloctypestr=stringloctypeloc=Location.ttypeattrs=attributelist(** {2 Default locations} *)valdefault_loc:locref(** Default value for all optional location arguments. *)valwith_default_loc:loc->(unit->'a)->'a(** Set the [default_loc] within the scope of the execution
of the provided function. *)(** {2 Constants} *)moduleConst:sigvalchar:char->constantvalstring:?quotation_delimiter:string->string->constantvalinteger:?suffix:char->string->constantvalint:?suffix:char->int->constantvalint32:?suffix:char->int32->constantvalint64:?suffix:char->int64->constantvalnativeint:?suffix:char->nativeint->constantvalfloat:?suffix:char->string->constantend(** {2 Core language} *)(** Type expressions *)moduleTyp:sigvalmk:?loc:loc->?attrs:attrs->core_type_desc->core_typevalattr:core_type->attribute->core_typevalany:?loc:loc->?attrs:attrs->unit->core_typevalvar:?loc:loc->?attrs:attrs->string->core_typevalarrow:?loc:loc->?attrs:attrs->arg_label->core_type->core_type->core_typevaltuple:?loc:loc->?attrs:attrs->core_typelist->core_typevalconstr:?loc:loc->?attrs:attrs->lid->core_typelist->core_typevalobject_:?loc:loc->?attrs:attrs->object_fieldlist->closed_flag->core_typevalclass_:?loc:loc->?attrs:attrs->lid->core_typelist->core_typevalalias:?loc:loc->?attrs:attrs->core_type->string->core_typevalvariant:?loc:loc->?attrs:attrs->row_fieldlist->closed_flag->labellistoption->core_typevalpoly:?loc:loc->?attrs:attrs->strlist->core_type->core_typevalpackage:?loc:loc->?attrs:attrs->lid->(lid*core_type)list->core_typevalextension:?loc:loc->?attrs:attrs->extension->core_typevalforce_poly:core_type->core_typevalvarify_constructors:strlist->core_type->core_type(** [varify_constructors newtypes te] is type expression [te], of which
any of nullary type constructor [tc] is replaced by type variable of
the same name, if [tc]'s name appears in [newtypes].
Raise [Syntaxerr.Variable_in_scope] if any type variable inside [te]
appears in [newtypes].
@since 4.05
*)end(** Patterns *)modulePat:sigvalmk:?loc:loc->?attrs:attrs->pattern_desc->patternvalattr:pattern->attribute->patternvalany:?loc:loc->?attrs:attrs->unit->patternvalvar:?loc:loc->?attrs:attrs->str->patternvalalias:?loc:loc->?attrs:attrs->pattern->str->patternvalconstant:?loc:loc->?attrs:attrs->constant->patternvalinterval:?loc:loc->?attrs:attrs->constant->constant->patternvaltuple:?loc:loc->?attrs:attrs->patternlist->patternvalconstruct:?loc:loc->?attrs:attrs->lid->patternoption->patternvalvariant:?loc:loc->?attrs:attrs->label->patternoption->patternvalrecord:?loc:loc->?attrs:attrs->(lid*pattern)list->closed_flag->patternvalarray:?loc:loc->?attrs:attrs->patternlist->patternvalor_:?loc:loc->?attrs:attrs->pattern->pattern->patternvalconstraint_:?loc:loc->?attrs:attrs->pattern->core_type->patternvaltype_:?loc:loc->?attrs:attrs->lid->patternvallazy_:?loc:loc->?attrs:attrs->pattern->patternvalunpack:?loc:loc->?attrs:attrs->str->patternvalopen_:?loc:loc->?attrs:attrs->lid->pattern->patternvalexception_:?loc:loc->?attrs:attrs->pattern->patternvalextension:?loc:loc->?attrs:attrs->extension->patternend(** Expressions *)moduleExp:sigvalmk:?loc:loc->?attrs:attrs->expression_desc->expressionvalattr:expression->attribute->expressionvalident:?loc:loc->?attrs:attrs->lid->expressionvalconstant:?loc:loc->?attrs:attrs->constant->expressionvallet_:?loc:loc->?attrs:attrs->rec_flag->value_bindinglist->expression->expressionvalfun_:?loc:loc->?attrs:attrs->arg_label->expressionoption->pattern->expression->expressionvalfunction_:?loc:loc->?attrs:attrs->caselist->expressionvalapply:?loc:loc->?attrs:attrs->expression->(arg_label*expression)list->expressionvalmatch_:?loc:loc->?attrs:attrs->expression->caselist->expressionvaltry_:?loc:loc->?attrs:attrs->expression->caselist->expressionvaltuple:?loc:loc->?attrs:attrs->expressionlist->expressionvalconstruct:?loc:loc->?attrs:attrs->lid->expressionoption->expressionvalvariant:?loc:loc->?attrs:attrs->label->expressionoption->expressionvalrecord:?loc:loc->?attrs:attrs->(lid*expression)list->expressionoption->expressionvalfield:?loc:loc->?attrs:attrs->expression->lid->expressionvalsetfield:?loc:loc->?attrs:attrs->expression->lid->expression->expressionvalarray:?loc:loc->?attrs:attrs->expressionlist->expressionvalifthenelse:?loc:loc->?attrs:attrs->expression->expression->expressionoption->expressionvalsequence:?loc:loc->?attrs:attrs->expression->expression->expressionvalwhile_:?loc:loc->?attrs:attrs->expression->expression->expressionvalfor_:?loc:loc->?attrs:attrs->pattern->expression->expression->direction_flag->expression->expressionvalcoerce:?loc:loc->?attrs:attrs->expression->core_typeoption->core_type->expressionvalconstraint_:?loc:loc->?attrs:attrs->expression->core_type->expressionvalsend:?loc:loc->?attrs:attrs->expression->str->expressionvalnew_:?loc:loc->?attrs:attrs->lid->expressionvalsetinstvar:?loc:loc->?attrs:attrs->str->expression->expressionvaloverride:?loc:loc->?attrs:attrs->(str*expression)list->expressionvalletmodule:?loc:loc->?attrs:attrs->str->module_expr->expression->expressionvalletexception:?loc:loc->?attrs:attrs->extension_constructor->expression->expressionvalassert_:?loc:loc->?attrs:attrs->expression->expressionvallazy_:?loc:loc->?attrs:attrs->expression->expressionvalpoly:?loc:loc->?attrs:attrs->expression->core_typeoption->expressionvalobject_:?loc:loc->?attrs:attrs->class_structure->expressionvalnewtype:?loc:loc->?attrs:attrs->str->expression->expressionvalpack:?loc:loc->?attrs:attrs->module_expr->expressionvalopen_:?loc:loc->?attrs:attrs->override_flag->lid->expression->expressionvalextension:?loc:loc->?attrs:attrs->extension->expressionvalunreachable:?loc:loc->?attrs:attrs->unit->expressionvalcase:pattern->?guard:expression->expression->caseend(** Value declarations *)moduleVal:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?prim:stringlist->str->core_type->value_descriptionend(** Type declarations *)moduleType:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->?params:(core_type*variance)list->?cstrs:(core_type*core_type*loc)list->?kind:type_kind->?priv:private_flag->?manifest:core_type->str->type_declarationvalconstructor:?loc:loc->?attrs:attrs->?info:info->?args:constructor_arguments->?res:core_type->str->constructor_declarationvalfield:?loc:loc->?attrs:attrs->?info:info->?mut:mutable_flag->str->core_type->label_declarationend(** Type extensions *)moduleTe:sigvalmk:?attrs:attrs->?docs:docs->?params:(core_type*variance)list->?priv:private_flag->lid->extension_constructorlist->type_extensionvalconstructor:?loc:loc->?attrs:attrs->?docs:docs->?info:info->str->extension_constructor_kind->extension_constructorvaldecl:?loc:loc->?attrs:attrs->?docs:docs->?info:info->?args:constructor_arguments->?res:core_type->str->extension_constructorvalrebind:?loc:loc->?attrs:attrs->?docs:docs->?info:info->str->lid->extension_constructorend(** {2 Module language} *)(** Module type expressions *)moduleMty:sigvalmk:?loc:loc->?attrs:attrs->module_type_desc->module_typevalattr:module_type->attribute->module_typevalident:?loc:loc->?attrs:attrs->lid->module_typevalalias:?loc:loc->?attrs:attrs->lid->module_typevalsignature:?loc:loc->?attrs:attrs->signature->module_typevalfunctor_:?loc:loc->?attrs:attrs->str->module_typeoption->module_type->module_typevalwith_:?loc:loc->?attrs:attrs->module_type->with_constraintlist->module_typevaltypeof_:?loc:loc->?attrs:attrs->module_expr->module_typevalextension:?loc:loc->?attrs:attrs->extension->module_typeend(** Module expressions *)moduleMod:sigvalmk:?loc:loc->?attrs:attrs->module_expr_desc->module_exprvalattr:module_expr->attribute->module_exprvalident:?loc:loc->?attrs:attrs->lid->module_exprvalstructure:?loc:loc->?attrs:attrs->structure->module_exprvalfunctor_:?loc:loc->?attrs:attrs->str->module_typeoption->module_expr->module_exprvalapply:?loc:loc->?attrs:attrs->module_expr->module_expr->module_exprvalconstraint_:?loc:loc->?attrs:attrs->module_expr->module_type->module_exprvalunpack:?loc:loc->?attrs:attrs->expression->module_exprvalextension:?loc:loc->?attrs:attrs->extension->module_exprend(** Signature items *)moduleSig:sigvalmk:?loc:loc->signature_item_desc->signature_itemvalvalue:?loc:loc->value_description->signature_itemvaltype_:?loc:loc->rec_flag->type_declarationlist->signature_itemvaltype_extension:?loc:loc->type_extension->signature_itemvalexception_:?loc:loc->extension_constructor->signature_itemvalmodule_:?loc:loc->module_declaration->signature_itemvalrec_module:?loc:loc->module_declarationlist->signature_itemvalmodtype:?loc:loc->module_type_declaration->signature_itemvalopen_:?loc:loc->open_description->signature_itemvalinclude_:?loc:loc->include_description->signature_itemvalclass_:?loc:loc->class_descriptionlist->signature_itemvalclass_type:?loc:loc->class_type_declarationlist->signature_itemvalextension:?loc:loc->?attrs:attrs->extension->signature_itemvalattribute:?loc:loc->attribute->signature_itemvaltext:text->signature_itemlistend(** Structure items *)moduleStr:sigvalmk:?loc:loc->structure_item_desc->structure_itemvaleval:?loc:loc->?attrs:attributes->expression->structure_itemvalvalue:?loc:loc->rec_flag->value_bindinglist->structure_itemvalprimitive:?loc:loc->value_description->structure_itemvaltype_:?loc:loc->rec_flag->type_declarationlist->structure_itemvaltype_extension:?loc:loc->type_extension->structure_itemvalexception_:?loc:loc->extension_constructor->structure_itemvalmodule_:?loc:loc->module_binding->structure_itemvalrec_module:?loc:loc->module_bindinglist->structure_itemvalmodtype:?loc:loc->module_type_declaration->structure_itemvalopen_:?loc:loc->open_description->structure_itemvalclass_:?loc:loc->class_declarationlist->structure_itemvalclass_type:?loc:loc->class_type_declarationlist->structure_itemvalinclude_:?loc:loc->include_declaration->structure_itemvalextension:?loc:loc->?attrs:attrs->extension->structure_itemvalattribute:?loc:loc->attribute->structure_itemvaltext:text->structure_itemlistend(** Module declarations *)moduleMd:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->str->module_type->module_declarationend(** Module type declarations *)moduleMtd:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->?typ:module_type->str->module_type_declarationend(** Module bindings *)moduleMb:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->str->module_expr->module_bindingend(** Opens *)moduleOpn:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?override:override_flag->lid->open_descriptionend(** Includes *)moduleIncl:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->'a->'ainclude_infosend(** Value bindings *)moduleVb:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->pattern->expression->value_bindingend(** {2 Class language} *)(** Class type expressions *)moduleCty:sigvalmk:?loc:loc->?attrs:attrs->class_type_desc->class_typevalattr:class_type->attribute->class_typevalconstr:?loc:loc->?attrs:attrs->lid->core_typelist->class_typevalsignature:?loc:loc->?attrs:attrs->class_signature->class_typevalarrow:?loc:loc->?attrs:attrs->arg_label->core_type->class_type->class_typevalextension:?loc:loc->?attrs:attrs->extension->class_typevalopen_:?loc:loc->?attrs:attrs->override_flag->lid->class_type->class_typeend(** Class type fields *)moduleCtf:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->class_type_field_desc->class_type_fieldvalattr:class_type_field->attribute->class_type_fieldvalinherit_:?loc:loc->?attrs:attrs->class_type->class_type_fieldvalval_:?loc:loc->?attrs:attrs->str->mutable_flag->virtual_flag->core_type->class_type_fieldvalmethod_:?loc:loc->?attrs:attrs->str->private_flag->virtual_flag->core_type->class_type_fieldvalconstraint_:?loc:loc->?attrs:attrs->core_type->core_type->class_type_fieldvalextension:?loc:loc->?attrs:attrs->extension->class_type_fieldvalattribute:?loc:loc->attribute->class_type_fieldvaltext:text->class_type_fieldlistend(** Class expressions *)moduleCl:sigvalmk:?loc:loc->?attrs:attrs->class_expr_desc->class_exprvalattr:class_expr->attribute->class_exprvalconstr:?loc:loc->?attrs:attrs->lid->core_typelist->class_exprvalstructure:?loc:loc->?attrs:attrs->class_structure->class_exprvalfun_:?loc:loc->?attrs:attrs->arg_label->expressionoption->pattern->class_expr->class_exprvalapply:?loc:loc->?attrs:attrs->class_expr->(arg_label*expression)list->class_exprvallet_:?loc:loc->?attrs:attrs->rec_flag->value_bindinglist->class_expr->class_exprvalconstraint_:?loc:loc->?attrs:attrs->class_expr->class_type->class_exprvalextension:?loc:loc->?attrs:attrs->extension->class_exprvalopen_:?loc:loc->?attrs:attrs->override_flag->lid->class_expr->class_exprend(** Class fields *)moduleCf:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->class_field_desc->class_fieldvalattr:class_field->attribute->class_fieldvalinherit_:?loc:loc->?attrs:attrs->override_flag->class_expr->stroption->class_fieldvalval_:?loc:loc->?attrs:attrs->str->mutable_flag->class_field_kind->class_fieldvalmethod_:?loc:loc->?attrs:attrs->str->private_flag->class_field_kind->class_fieldvalconstraint_:?loc:loc->?attrs:attrs->core_type->core_type->class_fieldvalinitializer_:?loc:loc->?attrs:attrs->expression->class_fieldvalextension:?loc:loc->?attrs:attrs->extension->class_fieldvalattribute:?loc:loc->attribute->class_fieldvaltext:text->class_fieldlistvalvirtual_:core_type->class_field_kindvalconcrete:override_flag->expression->class_field_kindend(** Classes *)moduleCi:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->?virt:virtual_flag->?params:(core_type*variance)list->str->'a->'aclass_infosend(** Class signatures *)moduleCsig:sigvalmk:core_type->class_type_fieldlist->class_signatureend(** Class structures *)moduleCstr:sigvalmk:pattern->class_fieldlist->class_structureendend=struct(** Helpers to produce Parsetree fragments *)openAsttypesopenParsetreeopenDocstringstypelid=Longident.tloctypestr=stringloctypeloc=Location.ttypeattrs=attributelistletdefault_loc=refLocation.noneletwith_default_loclf=letold=!default_locindefault_loc:=l;tryletr=f()indefault_loc:=old;rwithexn->default_loc:=old;raiseexnmoduleConst=structletinteger?suffixi=Pconst_integer(i,suffix)letint?suffixi=integer?suffix(string_of_inti)letint32?(suffix='l')i=integer~suffix(Int32.to_stringi)letint64?(suffix='L')i=integer~suffix(Int64.to_stringi)letnativeint?(suffix='n')i=integer~suffix(Nativeint.to_stringi)letfloat?suffixf=Pconst_float(f,suffix)letcharc=Pconst_charcletstring?quotation_delimiters=Pconst_string(s,quotation_delimiter)endmoduleTyp=structletmk?(loc=!default_loc)?(attrs=[])d={ptyp_desc=d;ptyp_loc=loc;ptyp_attributes=attrs}letattrda={dwithptyp_attributes=d.ptyp_attributes@[a]}letany?loc?attrs()=mk?loc?attrsPtyp_anyletvar?loc?attrsa=mk?loc?attrs(Ptyp_vara)letarrow?loc?attrsabc=mk?loc?attrs(Ptyp_arrow(a,b,c))lettuple?loc?attrsa=mk?loc?attrs(Ptyp_tuplea)letconstr?loc?attrsab=mk?loc?attrs(Ptyp_constr(a,b))letobject_?loc?attrsab=mk?loc?attrs(Ptyp_object(a,b))letclass_?loc?attrsab=mk?loc?attrs(Ptyp_class(a,b))letalias?loc?attrsab=mk?loc?attrs(Ptyp_alias(a,b))letvariant?loc?attrsabc=mk?loc?attrs(Ptyp_variant(a,b,c))letpoly?loc?attrsab=mk?loc?attrs(Ptyp_poly(a,b))letpackage?loc?attrsab=mk?loc?attrs(Ptyp_package(a,b))letextension?loc?attrsa=mk?loc?attrs(Ptyp_extensiona)letforce_polyt=matcht.ptyp_descwith|Ptyp_poly_->t|_->poly~loc:t.ptyp_loc[]t(* -> ghost? *)letvarify_constructorsvar_namest=letcheck_variablevllocv=ifList.memvvlthenraiseSyntaxerr.(Error(Variable_in_scope(loc,v)))inletvar_names=List.map(funv->v.txt)var_namesinletrecloopt=letdesc=matcht.ptyp_descwith|Ptyp_any->Ptyp_any|Ptyp_varx->check_variablevar_namest.ptyp_locx;Ptyp_varx|Ptyp_arrow(label,core_type,core_type')->Ptyp_arrow(label,loopcore_type,loopcore_type')|Ptyp_tuplelst->Ptyp_tuple(List.maplooplst)|Ptyp_constr({txt=Longident.Lidents;_},[])whenList.memsvar_names->Ptyp_vars|Ptyp_constr(longident,lst)->Ptyp_constr(longident,List.maplooplst)|Ptyp_object(lst,o)->Ptyp_object(List.maploop_object_fieldlst,o)|Ptyp_class(longident,lst)->Ptyp_class(longident,List.maplooplst)|Ptyp_alias(core_type,string)->check_variablevar_namest.ptyp_locstring;Ptyp_alias(loopcore_type,string)|Ptyp_variant(row_field_list,flag,lbl_lst_option)->Ptyp_variant(List.maploop_row_fieldrow_field_list,flag,lbl_lst_option)|Ptyp_poly(string_lst,core_type)->List.iter(funv->check_variablevar_namest.ptyp_locv.txt)string_lst;Ptyp_poly(string_lst,loopcore_type)|Ptyp_package(longident,lst)->Ptyp_package(longident,List.map(fun(n,typ)->(n,looptyp))lst)|Ptyp_extension(s,arg)->Ptyp_extension(s,arg)in{twithptyp_desc=desc}andloop_row_field=function|Rtag(label,attrs,flag,lst)->Rtag(label,attrs,flag,List.maplooplst)|Rinheritt->Rinherit(loopt)andloop_object_field=function|Otag(label,attrs,t)->Otag(label,attrs,loopt)|Oinheritt->Oinherit(loopt)inlooptendmodulePat=structletmk?(loc=!default_loc)?(attrs=[])d={ppat_desc=d;ppat_loc=loc;ppat_attributes=attrs}letattrda={dwithppat_attributes=d.ppat_attributes@[a]}letany?loc?attrs()=mk?loc?attrsPpat_anyletvar?loc?attrsa=mk?loc?attrs(Ppat_vara)letalias?loc?attrsab=mk?loc?attrs(Ppat_alias(a,b))letconstant?loc?attrsa=mk?loc?attrs(Ppat_constanta)letinterval?loc?attrsab=mk?loc?attrs(Ppat_interval(a,b))lettuple?loc?attrsa=mk?loc?attrs(Ppat_tuplea)letconstruct?loc?attrsab=mk?loc?attrs(Ppat_construct(a,b))letvariant?loc?attrsab=mk?loc?attrs(Ppat_variant(a,b))letrecord?loc?attrsab=mk?loc?attrs(Ppat_record(a,b))letarray?loc?attrsa=mk?loc?attrs(Ppat_arraya)letor_?loc?attrsab=mk?loc?attrs(Ppat_or(a,b))letconstraint_?loc?attrsab=mk?loc?attrs(Ppat_constraint(a,b))lettype_?loc?attrsa=mk?loc?attrs(Ppat_typea)letlazy_?loc?attrsa=mk?loc?attrs(Ppat_lazya)letunpack?loc?attrsa=mk?loc?attrs(Ppat_unpacka)letopen_?loc?attrsab=mk?loc?attrs(Ppat_open(a,b))letexception_?loc?attrsa=mk?loc?attrs(Ppat_exceptiona)letextension?loc?attrsa=mk?loc?attrs(Ppat_extensiona)endmoduleExp=structletmk?(loc=!default_loc)?(attrs=[])d={pexp_desc=d;pexp_loc=loc;pexp_attributes=attrs}letattrda={dwithpexp_attributes=d.pexp_attributes@[a]}letident?loc?attrsa=mk?loc?attrs(Pexp_identa)letconstant?loc?attrsa=mk?loc?attrs(Pexp_constanta)letlet_?loc?attrsabc=mk?loc?attrs(Pexp_let(a,b,c))letfun_?loc?attrsabcd=mk?loc?attrs(Pexp_fun(a,b,c,d))letfunction_?loc?attrsa=mk?loc?attrs(Pexp_functiona)letapply?loc?attrsab=mk?loc?attrs(Pexp_apply(a,b))letmatch_?loc?attrsab=mk?loc?attrs(Pexp_match(a,b))lettry_?loc?attrsab=mk?loc?attrs(Pexp_try(a,b))lettuple?loc?attrsa=mk?loc?attrs(Pexp_tuplea)letconstruct?loc?attrsab=mk?loc?attrs(Pexp_construct(a,b))letvariant?loc?attrsab=mk?loc?attrs(Pexp_variant(a,b))letrecord?loc?attrsab=mk?loc?attrs(Pexp_record(a,b))letfield?loc?attrsab=mk?loc?attrs(Pexp_field(a,b))letsetfield?loc?attrsabc=mk?loc?attrs(Pexp_setfield(a,b,c))letarray?loc?attrsa=mk?loc?attrs(Pexp_arraya)letifthenelse?loc?attrsabc=mk?loc?attrs(Pexp_ifthenelse(a,b,c))letsequence?loc?attrsab=mk?loc?attrs(Pexp_sequence(a,b))letwhile_?loc?attrsab=mk?loc?attrs(Pexp_while(a,b))letfor_?loc?attrsabcde=mk?loc?attrs(Pexp_for(a,b,c,d,e))letconstraint_?loc?attrsab=mk?loc?attrs(Pexp_constraint(a,b))letcoerce?loc?attrsabc=mk?loc?attrs(Pexp_coerce(a,b,c))letsend?loc?attrsab=mk?loc?attrs(Pexp_send(a,b))letnew_?loc?attrsa=mk?loc?attrs(Pexp_newa)letsetinstvar?loc?attrsab=mk?loc?attrs(Pexp_setinstvar(a,b))letoverride?loc?attrsa=mk?loc?attrs(Pexp_overridea)letletmodule?loc?attrsabc=mk?loc?attrs(Pexp_letmodule(a,b,c))letletexception?loc?attrsab=mk?loc?attrs(Pexp_letexception(a,b))letassert_?loc?attrsa=mk?loc?attrs(Pexp_asserta)letlazy_?loc?attrsa=mk?loc?attrs(Pexp_lazya)letpoly?loc?attrsab=mk?loc?attrs(Pexp_poly(a,b))letobject_?loc?attrsa=mk?loc?attrs(Pexp_objecta)letnewtype?loc?attrsab=mk?loc?attrs(Pexp_newtype(a,b))letpack?loc?attrsa=mk?loc?attrs(Pexp_packa)letopen_?loc?attrsabc=mk?loc?attrs(Pexp_open(a,b,c))letextension?loc?attrsa=mk?loc?attrs(Pexp_extensiona)letunreachable?loc?attrs()=mk?loc?attrsPexp_unreachableletcaselhs?guardrhs={pc_lhs=lhs;pc_guard=guard;pc_rhs=rhs;}endmoduleMty=structletmk?(loc=!default_loc)?(attrs=[])d={pmty_desc=d;pmty_loc=loc;pmty_attributes=attrs}letattrda={dwithpmty_attributes=d.pmty_attributes@[a]}letident?loc?attrsa=mk?loc?attrs(Pmty_identa)letalias?loc?attrsa=mk?loc?attrs(Pmty_aliasa)letsignature?loc?attrsa=mk?loc?attrs(Pmty_signaturea)letfunctor_?loc?attrsabc=mk?loc?attrs(Pmty_functor(a,b,c))letwith_?loc?attrsab=mk?loc?attrs(Pmty_with(a,b))lettypeof_?loc?attrsa=mk?loc?attrs(Pmty_typeofa)letextension?loc?attrsa=mk?loc?attrs(Pmty_extensiona)endmoduleMod=structletmk?(loc=!default_loc)?(attrs=[])d={pmod_desc=d;pmod_loc=loc;pmod_attributes=attrs}letattrda={dwithpmod_attributes=d.pmod_attributes@[a]}letident?loc?attrsx=mk?loc?attrs(Pmod_identx)letstructure?loc?attrsx=mk?loc?attrs(Pmod_structurex)letfunctor_?loc?attrsargarg_tybody=mk?loc?attrs(Pmod_functor(arg,arg_ty,body))letapply?loc?attrsm1m2=mk?loc?attrs(Pmod_apply(m1,m2))letconstraint_?loc?attrsmmty=mk?loc?attrs(Pmod_constraint(m,mty))letunpack?loc?attrse=mk?loc?attrs(Pmod_unpacke)letextension?loc?attrsa=mk?loc?attrs(Pmod_extensiona)endmoduleSig=structletmk?(loc=!default_loc)d={psig_desc=d;psig_loc=loc}letvalue?loca=mk?loc(Psig_valuea)lettype_?locrec_flaga=mk?loc(Psig_type(rec_flag,a))lettype_extension?loca=mk?loc(Psig_typexta)letexception_?loca=mk?loc(Psig_exceptiona)letmodule_?loca=mk?loc(Psig_modulea)letrec_module?loca=mk?loc(Psig_recmodulea)letmodtype?loca=mk?loc(Psig_modtypea)letopen_?loca=mk?loc(Psig_opena)letinclude_?loca=mk?loc(Psig_includea)letclass_?loca=mk?loc(Psig_classa)letclass_type?loca=mk?loc(Psig_class_typea)letextension?loc?(attrs=[])a=mk?loc(Psig_extension(a,attrs))letattribute?loca=mk?loc(Psig_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtendmoduleStr=structletmk?(loc=!default_loc)d={pstr_desc=d;pstr_loc=loc}leteval?loc?(attrs=[])a=mk?loc(Pstr_eval(a,attrs))letvalue?locab=mk?loc(Pstr_value(a,b))letprimitive?loca=mk?loc(Pstr_primitivea)lettype_?locrec_flaga=mk?loc(Pstr_type(rec_flag,a))lettype_extension?loca=mk?loc(Pstr_typexta)letexception_?loca=mk?loc(Pstr_exceptiona)letmodule_?loca=mk?loc(Pstr_modulea)letrec_module?loca=mk?loc(Pstr_recmodulea)letmodtype?loca=mk?loc(Pstr_modtypea)letopen_?loca=mk?loc(Pstr_opena)letclass_?loca=mk?loc(Pstr_classa)letclass_type?loca=mk?loc(Pstr_class_typea)letinclude_?loca=mk?loc(Pstr_includea)letextension?loc?(attrs=[])a=mk?loc(Pstr_extension(a,attrs))letattribute?loca=mk?loc(Pstr_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtendmoduleCl=structletmk?(loc=!default_loc)?(attrs=[])d={pcl_desc=d;pcl_loc=loc;pcl_attributes=attrs;}letattrda={dwithpcl_attributes=d.pcl_attributes@[a]}letconstr?loc?attrsab=mk?loc?attrs(Pcl_constr(a,b))letstructure?loc?attrsa=mk?loc?attrs(Pcl_structurea)letfun_?loc?attrsabcd=mk?loc?attrs(Pcl_fun(a,b,c,d))letapply?loc?attrsab=mk?loc?attrs(Pcl_apply(a,b))letlet_?loc?attrsabc=mk?loc?attrs(Pcl_let(a,b,c))letconstraint_?loc?attrsab=mk?loc?attrs(Pcl_constraint(a,b))letextension?loc?attrsa=mk?loc?attrs(Pcl_extensiona)letopen_?loc?attrsabc=mk?loc?attrs(Pcl_open(a,b,c))endmoduleCty=structletmk?(loc=!default_loc)?(attrs=[])d={pcty_desc=d;pcty_loc=loc;pcty_attributes=attrs;}letattrda={dwithpcty_attributes=d.pcty_attributes@[a]}letconstr?loc?attrsab=mk?loc?attrs(Pcty_constr(a,b))letsignature?loc?attrsa=mk?loc?attrs(Pcty_signaturea)letarrow?loc?attrsabc=mk?loc?attrs(Pcty_arrow(a,b,c))letextension?loc?attrsa=mk?loc?attrs(Pcty_extensiona)letopen_?loc?attrsabc=mk?loc?attrs(Pcty_open(a,b,c))endmoduleCtf=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)d={pctf_desc=d;pctf_loc=loc;pctf_attributes=add_docs_attrsdocsattrs;}letinherit_?loc?attrsa=mk?loc?attrs(Pctf_inherita)letval_?loc?attrsabcd=mk?loc?attrs(Pctf_val(a,b,c,d))letmethod_?loc?attrsabcd=mk?loc?attrs(Pctf_method(a,b,c,d))letconstraint_?loc?attrsab=mk?loc?attrs(Pctf_constraint(a,b))letextension?loc?attrsa=mk?loc?attrs(Pctf_extensiona)letattribute?loca=mk?loc(Pctf_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtletattrda={dwithpctf_attributes=d.pctf_attributes@[a]}endmoduleCf=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)d={pcf_desc=d;pcf_loc=loc;pcf_attributes=add_docs_attrsdocsattrs;}letinherit_?loc?attrsabc=mk?loc?attrs(Pcf_inherit(a,b,c))letval_?loc?attrsabc=mk?loc?attrs(Pcf_val(a,b,c))letmethod_?loc?attrsabc=mk?loc?attrs(Pcf_method(a,b,c))letconstraint_?loc?attrsab=mk?loc?attrs(Pcf_constraint(a,b))letinitializer_?loc?attrsa=mk?loc?attrs(Pcf_initializera)letextension?loc?attrsa=mk?loc?attrs(Pcf_extensiona)letattribute?loca=mk?loc(Pcf_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtletvirtual_ct=Cfk_virtualctletconcreteoe=Cfk_concrete(o,e)letattrda={dwithpcf_attributes=d.pcf_attributes@[a]}endmoduleVal=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(prim=[])nametyp={pval_name=name;pval_type=typ;pval_attributes=add_docs_attrsdocsattrs;pval_loc=loc;pval_prim=prim;}endmoduleMd=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])nametyp={pmd_name=name;pmd_type=typ;pmd_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pmd_loc=loc;}endmoduleMtd=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])?typname={pmtd_name=name;pmtd_type=typ;pmtd_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pmtd_loc=loc;}endmoduleMb=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])nameexpr={pmb_name=name;pmb_expr=expr;pmb_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pmb_loc=loc;}endmoduleOpn=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(override=Fresh)lid={popen_lid=lid;popen_override=override;popen_loc=loc;popen_attributes=add_docs_attrsdocsattrs;}endmoduleIncl=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)mexpr={pincl_mod=mexpr;pincl_loc=loc;pincl_attributes=add_docs_attrsdocsattrs;}endmoduleVb=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])patexpr={pvb_pat=pat;pvb_expr=expr;pvb_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pvb_loc=loc;}endmoduleCi=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])?(virt=Concrete)?(params=[])nameexpr={pci_virt=virt;pci_params=params;pci_name=name;pci_expr=expr;pci_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pci_loc=loc;}endmoduleType=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])?(params=[])?(cstrs=[])?(kind=Ptype_abstract)?(priv=Public)?manifestname={ptype_name=name;ptype_params=params;ptype_cstrs=cstrs;ptype_kind=kind;ptype_private=priv;ptype_manifest=manifest;ptype_attributes=add_text_attrstext(add_docs_attrsdocsattrs);ptype_loc=loc;}letconstructor?(loc=!default_loc)?(attrs=[])?(info=empty_info)?(args=Pcstr_tuple[])?resname={pcd_name=name;pcd_args=args;pcd_res=res;pcd_loc=loc;pcd_attributes=add_info_attrsinfoattrs;}letfield?(loc=!default_loc)?(attrs=[])?(info=empty_info)?(mut=Immutable)nametyp={pld_name=name;pld_mutable=mut;pld_type=typ;pld_loc=loc;pld_attributes=add_info_attrsinfoattrs;}end(** Type extensions *)moduleTe=structletmk?(attrs=[])?(docs=empty_docs)?(params=[])?(priv=Public)pathconstructors={ptyext_path=path;ptyext_params=params;ptyext_constructors=constructors;ptyext_private=priv;ptyext_attributes=add_docs_attrsdocsattrs;}letconstructor?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(info=empty_info)namekind={pext_name=name;pext_kind=kind;pext_loc=loc;pext_attributes=add_docs_attrsdocs(add_info_attrsinfoattrs);}letdecl?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(info=empty_info)?(args=Pcstr_tuple[])?resname={pext_name=name;pext_kind=Pext_decl(args,res);pext_loc=loc;pext_attributes=add_docs_attrsdocs(add_info_attrsinfoattrs);}letrebind?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(info=empty_info)namelid={pext_name=name;pext_kind=Pext_rebindlid;pext_loc=loc;pext_attributes=add_docs_attrsdocs(add_info_attrsinfoattrs);}endmoduleCsig=structletmkselffields={pcsig_self=self;pcsig_fields=fields;}endmoduleCstr=structletmkselffields={pcstr_self=self;pcstr_fields=fields;}endendmoduleAst_mapper:sig(** The interface of a -ppx rewriter
A -ppx rewriter is a program that accepts a serialized abstract syntax
tree and outputs another, possibly modified, abstract syntax tree.
This module encapsulates the interface between the compiler and
the -ppx rewriters, handling such details as the serialization format,
forwarding of command-line flags, and storing state.
{!mapper} allows to implement AST rewriting using open recursion.
A typical mapper would be based on {!default_mapper}, a deep
identity mapper, and will fall back on it for handling the syntax it
does not modify. For example:
{[
open Asttypes
open Parsetree
open Ast_mapper
let test_mapper argv =
{ default_mapper with
expr = fun mapper expr ->
match expr with
| { pexp_desc = Pexp_extension ({ txt = "test" }, PStr [])} ->
Ast_helper.Exp.constant (Const_int 42)
| other -> default_mapper.expr mapper other; }
let () =
register "ppx_test" test_mapper]}
This -ppx rewriter, which replaces [[%test]] in expressions with
the constant [42], can be compiled using
[ocamlc -o ppx_test -I +compiler-libs ocamlcommon.cma ppx_test.ml].
*)openParsetree(** {2 A generic Parsetree mapper} *)typemapper(*IF_CURRENT = Ast_mapper.mapper*)={attribute:mapper->attribute->attribute;attributes:mapper->attributelist->attributelist;case:mapper->case->case;cases:mapper->caselist->caselist;class_declaration:mapper->class_declaration->class_declaration;class_description:mapper->class_description->class_description;class_expr:mapper->class_expr->class_expr;class_field:mapper->class_field->class_field;class_signature:mapper->class_signature->class_signature;class_structure:mapper->class_structure->class_structure;class_type:mapper->class_type->class_type;class_type_declaration:mapper->class_type_declaration->class_type_declaration;class_type_field:mapper->class_type_field->class_type_field;constructor_declaration:mapper->constructor_declaration->constructor_declaration;expr:mapper->expression->expression;extension:mapper->extension->extension;extension_constructor:mapper->extension_constructor->extension_constructor;include_declaration:mapper->include_declaration->include_declaration;include_description:mapper->include_description->include_description;label_declaration:mapper->label_declaration->label_declaration;location:mapper->Location.t->Location.t;module_binding:mapper->module_binding->module_binding;module_declaration:mapper->module_declaration->module_declaration;module_expr:mapper->module_expr->module_expr;module_type:mapper->module_type->module_type;module_type_declaration:mapper->module_type_declaration->module_type_declaration;open_description:mapper->open_description->open_description;pat:mapper->pattern->pattern;payload:mapper->payload->payload;signature:mapper->signature->signature;signature_item:mapper->signature_item->signature_item;structure:mapper->structure->structure;structure_item:mapper->structure_item->structure_item;typ:mapper->core_type->core_type;type_declaration:mapper->type_declaration->type_declaration;type_extension:mapper->type_extension->type_extension;type_kind:mapper->type_kind->type_kind;value_binding:mapper->value_binding->value_binding;value_description:mapper->value_description->value_description;with_constraint:mapper->with_constraint->with_constraint;}(** A mapper record implements one "method" per syntactic category,
using an open recursion style: each method takes as its first
argument the mapper to be applied to children in the syntax
tree. *)valdefault_mapper:mapper(** A default mapper, which implements a "deep identity" mapping. *)(** {2 Convenience functions to write mappers} *)valmap_opt:('a->'b)->'aoption->'boptionvalextension_of_error:Locations.location_error->extension(** Encode an error into an 'ocaml.error' extension node which can be
inserted in a generated Parsetree. The compiler will be
responsible for reporting the error. *)valattribute_of_warning:Location.t->string->attribute(** Encode a warning message into an 'ocaml.ppwarning' attribute which can be
inserted in a generated Parsetree. The compiler will be
responsible for reporting the warning. *)includeLocations.Helpers_intfend=struct(* A generic Parsetree mapping class *)(*
[@@@ocaml.warning "+9"]
(* Ensure that record patterns don't miss any field. *)
*)openParsetreeopenAst_helperopenLocationtypemapper(*IF_CURRENT = Ast_mapper.mapper*)={attribute:mapper->attribute->attribute;attributes:mapper->attributelist->attributelist;case:mapper->case->case;cases:mapper->caselist->caselist;class_declaration:mapper->class_declaration->class_declaration;class_description:mapper->class_description->class_description;class_expr:mapper->class_expr->class_expr;class_field:mapper->class_field->class_field;class_signature:mapper->class_signature->class_signature;class_structure:mapper->class_structure->class_structure;class_type:mapper->class_type->class_type;class_type_declaration:mapper->class_type_declaration->class_type_declaration;class_type_field:mapper->class_type_field->class_type_field;constructor_declaration:mapper->constructor_declaration->constructor_declaration;expr:mapper->expression->expression;extension:mapper->extension->extension;extension_constructor:mapper->extension_constructor->extension_constructor;include_declaration:mapper->include_declaration->include_declaration;include_description:mapper->include_description->include_description;label_declaration:mapper->label_declaration->label_declaration;location:mapper->Location.t->Location.t;module_binding:mapper->module_binding->module_binding;module_declaration:mapper->module_declaration->module_declaration;module_expr:mapper->module_expr->module_expr;module_type:mapper->module_type->module_type;module_type_declaration:mapper->module_type_declaration->module_type_declaration;open_description:mapper->open_description->open_description;pat:mapper->pattern->pattern;payload:mapper->payload->payload;signature:mapper->signature->signature;signature_item:mapper->signature_item->signature_item;structure:mapper->structure->structure;structure_item:mapper->structure_item->structure_item;typ:mapper->core_type->core_type;type_declaration:mapper->type_declaration->type_declaration;type_extension:mapper->type_extension->type_extension;type_kind:mapper->type_kind->type_kind;value_binding:mapper->value_binding->value_binding;value_description:mapper->value_description->value_description;with_constraint:mapper->with_constraint->with_constraint;}letmap_fstf(x,y)=(fx,y)letmap_sndf(x,y)=(x,fy)letmap_tuplef1f2(x,y)=(f1x,f2y)letmap_tuple3f1f2f3(x,y,z)=(f1x,f2y,f3z)letmap_optf=functionNone->None|Somex->Some(fx)letmap_locsub{loc;txt}={loc=sub.locationsubloc;txt}moduleT=struct(* Type expressions for the core language *)letrow_fieldsub=function|Rtag(l,attrs,b,tl)->Rtag(map_locsubl,sub.attributessubattrs,b,List.map(sub.typsub)tl)|Rinheritt->Rinherit(sub.typsubt)letobject_fieldsub=function|Otag(l,attrs,t)->Otag(map_locsubl,sub.attributessubattrs,sub.typsubt)|Oinheritt->Oinherit(sub.typsubt)letmapsub{ptyp_desc=desc;ptyp_loc=loc;ptyp_attributes=attrs}=letopenTypinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Ptyp_any->any~loc~attrs()|Ptyp_vars->var~loc~attrss|Ptyp_arrow(lab,t1,t2)->arrow~loc~attrslab(sub.typsubt1)(sub.typsubt2)|Ptyp_tupletyl->tuple~loc~attrs(List.map(sub.typsub)tyl)|Ptyp_constr(lid,tl)->constr~loc~attrs(map_locsublid)(List.map(sub.typsub)tl)|Ptyp_object(l,o)->object_~loc~attrs(List.map(object_fieldsub)l)o|Ptyp_class(lid,tl)->class_~loc~attrs(map_locsublid)(List.map(sub.typsub)tl)|Ptyp_alias(t,s)->alias~loc~attrs(sub.typsubt)s|Ptyp_variant(rl,b,ll)->variant~loc~attrs(List.map(row_fieldsub)rl)bll|Ptyp_poly(sl,t)->poly~loc~attrs(List.map(map_locsub)sl)(sub.typsubt)|Ptyp_package(lid,l)->package~loc~attrs(map_locsublid)(List.map(map_tuple(map_locsub)(sub.typsub))l)|Ptyp_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_type_declarationsub{ptype_name;ptype_params;ptype_cstrs;ptype_kind;ptype_private;ptype_manifest;ptype_attributes;ptype_loc}=Type.mk(map_locsubptype_name)~params:(List.map(map_fst(sub.typsub))ptype_params)~priv:ptype_private~cstrs:(List.map(map_tuple3(sub.typsub)(sub.typsub)(sub.locationsub))ptype_cstrs)~kind:(sub.type_kindsubptype_kind)?manifest:(map_opt(sub.typsub)ptype_manifest)~loc:(sub.locationsubptype_loc)~attrs:(sub.attributessubptype_attributes)letmap_type_kindsub=function|Ptype_abstract->Ptype_abstract|Ptype_variantl->Ptype_variant(List.map(sub.constructor_declarationsub)l)|Ptype_recordl->Ptype_record(List.map(sub.label_declarationsub)l)|Ptype_open->Ptype_openletmap_constructor_argumentssub=function|Pcstr_tuplel->Pcstr_tuple(List.map(sub.typsub)l)|Pcstr_recordl->Pcstr_record(List.map(sub.label_declarationsub)l)letmap_type_extensionsub{ptyext_path;ptyext_params;ptyext_constructors;ptyext_private;ptyext_attributes}=Te.mk(map_locsubptyext_path)(List.map(sub.extension_constructorsub)ptyext_constructors)~params:(List.map(map_fst(sub.typsub))ptyext_params)~priv:ptyext_private~attrs:(sub.attributessubptyext_attributes)letmap_extension_constructor_kindsub=functionPext_decl(ctl,cto)->Pext_decl(map_constructor_argumentssubctl,map_opt(sub.typsub)cto)|Pext_rebindli->Pext_rebind(map_locsubli)letmap_extension_constructorsub{pext_name;pext_kind;pext_loc;pext_attributes}=Te.constructor(map_locsubpext_name)(map_extension_constructor_kindsubpext_kind)~loc:(sub.locationsubpext_loc)~attrs:(sub.attributessubpext_attributes)endmoduleCT=struct(* Type expressions for the class language *)letmapsub{pcty_loc=loc;pcty_desc=desc;pcty_attributes=attrs}=letopenCtyinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pcty_constr(lid,tys)->constr~loc~attrs(map_locsublid)(List.map(sub.typsub)tys)|Pcty_signaturex->signature~loc~attrs(sub.class_signaturesubx)|Pcty_arrow(lab,t,ct)->arrow~loc~attrslab(sub.typsubt)(sub.class_typesubct)|Pcty_extensionx->extension~loc~attrs(sub.extensionsubx)|Pcty_open(ovf,lid,ct)->open_~loc~attrsovf(map_locsublid)(sub.class_typesubct)letmap_fieldsub{pctf_desc=desc;pctf_loc=loc;pctf_attributes=attrs}=letopenCtfinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pctf_inheritct->inherit_~loc~attrs(sub.class_typesubct)|Pctf_val(s,m,v,t)->val_~loc~attrs(map_locsubs)mv(sub.typsubt)|Pctf_method(s,p,v,t)->method_~loc~attrs(map_locsubs)pv(sub.typsubt)|Pctf_constraint(t1,t2)->constraint_~loc~attrs(sub.typsubt1)(sub.typsubt2)|Pctf_attributex->attribute~loc(sub.attributesubx)|Pctf_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_signaturesub{pcsig_self;pcsig_fields}=Csig.mk(sub.typsubpcsig_self)(List.map(sub.class_type_fieldsub)pcsig_fields)endmoduleMT=struct(* Type expressions for the module language *)letmapsub{pmty_desc=desc;pmty_loc=loc;pmty_attributes=attrs}=letopenMtyinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pmty_idents->ident~loc~attrs(map_locsubs)|Pmty_aliass->alias~loc~attrs(map_locsubs)|Pmty_signaturesg->signature~loc~attrs(sub.signaturesubsg)|Pmty_functor(s,mt1,mt2)->functor_~loc~attrs(map_locsubs)(Migrate_parsetree_compiler_functions.may_map(sub.module_typesub)mt1)(sub.module_typesubmt2)|Pmty_with(mt,l)->with_~loc~attrs(sub.module_typesubmt)(List.map(sub.with_constraintsub)l)|Pmty_typeofme->typeof_~loc~attrs(sub.module_exprsubme)|Pmty_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_with_constraintsub=function|Pwith_type(lid,d)->Pwith_type(map_locsublid,sub.type_declarationsubd)|Pwith_module(lid,lid2)->Pwith_module(map_locsublid,map_locsublid2)|Pwith_typesubst(lid,d)->Pwith_typesubst(map_locsublid,sub.type_declarationsubd)|Pwith_modsubst(s,lid)->Pwith_modsubst(map_locsubs,map_locsublid)letmap_signature_itemsub{psig_desc=desc;psig_loc=loc}=letopenSiginletloc=sub.locationsublocinmatchdescwith|Psig_valuevd->value~loc(sub.value_descriptionsubvd)|Psig_type(rf,l)->type_~locrf(List.map(sub.type_declarationsub)l)|Psig_typextte->type_extension~loc(sub.type_extensionsubte)|Psig_exceptioned->exception_~loc(sub.extension_constructorsubed)|Psig_modulex->module_~loc(sub.module_declarationsubx)|Psig_recmodulel->rec_module~loc(List.map(sub.module_declarationsub)l)|Psig_modtypex->modtype~loc(sub.module_type_declarationsubx)|Psig_openx->open_~loc(sub.open_descriptionsubx)|Psig_includex->include_~loc(sub.include_descriptionsubx)|Psig_classl->class_~loc(List.map(sub.class_descriptionsub)l)|Psig_class_typel->class_type~loc(List.map(sub.class_type_declarationsub)l)|Psig_extension(x,attrs)->extension~loc(sub.extensionsubx)~attrs:(sub.attributessubattrs)|Psig_attributex->attribute~loc(sub.attributesubx)endmoduleM=struct(* Value expressions for the module language *)letmapsub{pmod_loc=loc;pmod_desc=desc;pmod_attributes=attrs}=letopenModinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pmod_identx->ident~loc~attrs(map_locsubx)|Pmod_structurestr->structure~loc~attrs(sub.structuresubstr)|Pmod_functor(arg,arg_ty,body)->functor_~loc~attrs(map_locsubarg)(Migrate_parsetree_compiler_functions.may_map(sub.module_typesub)arg_ty)(sub.module_exprsubbody)|Pmod_apply(m1,m2)->apply~loc~attrs(sub.module_exprsubm1)(sub.module_exprsubm2)|Pmod_constraint(m,mty)->constraint_~loc~attrs(sub.module_exprsubm)(sub.module_typesubmty)|Pmod_unpacke->unpack~loc~attrs(sub.exprsube)|Pmod_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_structure_itemsub{pstr_loc=loc;pstr_desc=desc}=letopenStrinletloc=sub.locationsublocinmatchdescwith|Pstr_eval(x,attrs)->eval~loc~attrs:(sub.attributessubattrs)(sub.exprsubx)|Pstr_value(r,vbs)->value~locr(List.map(sub.value_bindingsub)vbs)|Pstr_primitivevd->primitive~loc(sub.value_descriptionsubvd)|Pstr_type(rf,l)->type_~locrf(List.map(sub.type_declarationsub)l)|Pstr_typextte->type_extension~loc(sub.type_extensionsubte)|Pstr_exceptioned->exception_~loc(sub.extension_constructorsubed)|Pstr_modulex->module_~loc(sub.module_bindingsubx)|Pstr_recmodulel->rec_module~loc(List.map(sub.module_bindingsub)l)|Pstr_modtypex->modtype~loc(sub.module_type_declarationsubx)|Pstr_openx->open_~loc(sub.open_descriptionsubx)|Pstr_classl->class_~loc(List.map(sub.class_declarationsub)l)|Pstr_class_typel->class_type~loc(List.map(sub.class_type_declarationsub)l)|Pstr_includex->include_~loc(sub.include_declarationsubx)|Pstr_extension(x,attrs)->extension~loc(sub.extensionsubx)~attrs:(sub.attributessubattrs)|Pstr_attributex->attribute~loc(sub.attributesubx)endmoduleE=struct(* Value expressions for the core language *)letmapsub{pexp_loc=loc;pexp_desc=desc;pexp_attributes=attrs}=letopenExpinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pexp_identx->ident~loc~attrs(map_locsubx)|Pexp_constantx->constant~loc~attrsx|Pexp_let(r,vbs,e)->let_~loc~attrsr(List.map(sub.value_bindingsub)vbs)(sub.exprsube)|Pexp_fun(lab,def,p,e)->fun_~loc~attrslab(map_opt(sub.exprsub)def)(sub.patsubp)(sub.exprsube)|Pexp_functionpel->function_~loc~attrs(sub.casessubpel)|Pexp_apply(e,l)->apply~loc~attrs(sub.exprsube)(List.map(map_snd(sub.exprsub))l)|Pexp_match(e,pel)->match_~loc~attrs(sub.exprsube)(sub.casessubpel)|Pexp_try(e,pel)->try_~loc~attrs(sub.exprsube)(sub.casessubpel)|Pexp_tupleel->tuple~loc~attrs(List.map(sub.exprsub)el)|Pexp_construct(lid,arg)->construct~loc~attrs(map_locsublid)(map_opt(sub.exprsub)arg)|Pexp_variant(lab,eo)->variant~loc~attrslab(map_opt(sub.exprsub)eo)|Pexp_record(l,eo)->record~loc~attrs(List.map(map_tuple(map_locsub)(sub.exprsub))l)(map_opt(sub.exprsub)eo)|Pexp_field(e,lid)->field~loc~attrs(sub.exprsube)(map_locsublid)|Pexp_setfield(e1,lid,e2)->setfield~loc~attrs(sub.exprsube1)(map_locsublid)(sub.exprsube2)|Pexp_arrayel->array~loc~attrs(List.map(sub.exprsub)el)|Pexp_ifthenelse(e1,e2,e3)->ifthenelse~loc~attrs(sub.exprsube1)(sub.exprsube2)(map_opt(sub.exprsub)e3)|Pexp_sequence(e1,e2)->sequence~loc~attrs(sub.exprsube1)(sub.exprsube2)|Pexp_while(e1,e2)->while_~loc~attrs(sub.exprsube1)(sub.exprsube2)|Pexp_for(p,e1,e2,d,e3)->for_~loc~attrs(sub.patsubp)(sub.exprsube1)(sub.exprsube2)d(sub.exprsube3)|Pexp_coerce(e,t1,t2)->coerce~loc~attrs(sub.exprsube)(map_opt(sub.typsub)t1)(sub.typsubt2)|Pexp_constraint(e,t)->constraint_~loc~attrs(sub.exprsube)(sub.typsubt)|Pexp_send(e,s)->send~loc~attrs(sub.exprsube)(map_locsubs)|Pexp_newlid->new_~loc~attrs(map_locsublid)|Pexp_setinstvar(s,e)->setinstvar~loc~attrs(map_locsubs)(sub.exprsube)|Pexp_overridesel->override~loc~attrs(List.map(map_tuple(map_locsub)(sub.exprsub))sel)|Pexp_letmodule(s,me,e)->letmodule~loc~attrs(map_locsubs)(sub.module_exprsubme)(sub.exprsube)|Pexp_letexception(cd,e)->letexception~loc~attrs(sub.extension_constructorsubcd)(sub.exprsube)|Pexp_asserte->assert_~loc~attrs(sub.exprsube)|Pexp_lazye->lazy_~loc~attrs(sub.exprsube)|Pexp_poly(e,t)->poly~loc~attrs(sub.exprsube)(map_opt(sub.typsub)t)|Pexp_objectcls->object_~loc~attrs(sub.class_structuresubcls)|Pexp_newtype(s,e)->newtype~loc~attrs(map_locsubs)(sub.exprsube)|Pexp_packme->pack~loc~attrs(sub.module_exprsubme)|Pexp_open(ovf,lid,e)->open_~loc~attrsovf(map_locsublid)(sub.exprsube)|Pexp_extensionx->extension~loc~attrs(sub.extensionsubx)|Pexp_unreachable->unreachable~loc~attrs()endmoduleP=struct(* Patterns *)letmapsub{ppat_desc=desc;ppat_loc=loc;ppat_attributes=attrs}=letopenPatinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Ppat_any->any~loc~attrs()|Ppat_vars->var~loc~attrs(map_locsubs)|Ppat_alias(p,s)->alias~loc~attrs(sub.patsubp)(map_locsubs)|Ppat_constantc->constant~loc~attrsc|Ppat_interval(c1,c2)->interval~loc~attrsc1c2|Ppat_tuplepl->tuple~loc~attrs(List.map(sub.patsub)pl)|Ppat_construct(l,p)->construct~loc~attrs(map_locsubl)(map_opt(sub.patsub)p)|Ppat_variant(l,p)->variant~loc~attrsl(map_opt(sub.patsub)p)|Ppat_record(lpl,cf)->record~loc~attrs(List.map(map_tuple(map_locsub)(sub.patsub))lpl)cf|Ppat_arraypl->array~loc~attrs(List.map(sub.patsub)pl)|Ppat_or(p1,p2)->or_~loc~attrs(sub.patsubp1)(sub.patsubp2)|Ppat_constraint(p,t)->constraint_~loc~attrs(sub.patsubp)(sub.typsubt)|Ppat_types->type_~loc~attrs(map_locsubs)|Ppat_lazyp->lazy_~loc~attrs(sub.patsubp)|Ppat_unpacks->unpack~loc~attrs(map_locsubs)|Ppat_open(lid,p)->open_~loc~attrs(map_locsublid)(sub.patsubp)|Ppat_exceptionp->exception_~loc~attrs(sub.patsubp)|Ppat_extensionx->extension~loc~attrs(sub.extensionsubx)endmoduleCE=struct(* Value expressions for the class language *)letmapsub{pcl_loc=loc;pcl_desc=desc;pcl_attributes=attrs}=letopenClinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pcl_constr(lid,tys)->constr~loc~attrs(map_locsublid)(List.map(sub.typsub)tys)|Pcl_structures->structure~loc~attrs(sub.class_structuresubs)|Pcl_fun(lab,e,p,ce)->fun_~loc~attrslab(map_opt(sub.exprsub)e)(sub.patsubp)(sub.class_exprsubce)|Pcl_apply(ce,l)->apply~loc~attrs(sub.class_exprsubce)(List.map(map_snd(sub.exprsub))l)|Pcl_let(r,vbs,ce)->let_~loc~attrsr(List.map(sub.value_bindingsub)vbs)(sub.class_exprsubce)|Pcl_constraint(ce,ct)->constraint_~loc~attrs(sub.class_exprsubce)(sub.class_typesubct)|Pcl_extensionx->extension~loc~attrs(sub.extensionsubx)|Pcl_open(ovf,lid,ce)->open_~loc~attrsovf(map_locsublid)(sub.class_exprsubce)letmap_kindsub=function|Cfk_concrete(o,e)->Cfk_concrete(o,sub.exprsube)|Cfk_virtualt->Cfk_virtual(sub.typsubt)letmap_fieldsub{pcf_desc=desc;pcf_loc=loc;pcf_attributes=attrs}=letopenCfinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pcf_inherit(o,ce,s)->inherit_~loc~attrso(sub.class_exprsubce)(map_opt(map_locsub)s)|Pcf_val(s,m,k)->val_~loc~attrs(map_locsubs)m(map_kindsubk)|Pcf_method(s,p,k)->method_~loc~attrs(map_locsubs)p(map_kindsubk)|Pcf_constraint(t1,t2)->constraint_~loc~attrs(sub.typsubt1)(sub.typsubt2)|Pcf_initializere->initializer_~loc~attrs(sub.exprsube)|Pcf_attributex->attribute~loc(sub.attributesubx)|Pcf_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_structuresub{pcstr_self;pcstr_fields}={pcstr_self=sub.patsubpcstr_self;pcstr_fields=List.map(sub.class_fieldsub)pcstr_fields;}letclass_infossubf{pci_virt;pci_params=pl;pci_name;pci_expr;pci_loc;pci_attributes}=Ci.mk~virt:pci_virt~params:(List.map(map_fst(sub.typsub))pl)(map_locsubpci_name)(fpci_expr)~loc:(sub.locationsubpci_loc)~attrs:(sub.attributessubpci_attributes)end(* Now, a generic AST mapper, to be extended to cover all kinds and
cases of the OCaml grammar. The default behavior of the mapper is
the identity. *)letdefault_mapper={structure=(funthisl->List.map(this.structure_itemthis)l);structure_item=M.map_structure_item;module_expr=M.map;signature=(funthisl->List.map(this.signature_itemthis)l);signature_item=MT.map_signature_item;module_type=MT.map;with_constraint=MT.map_with_constraint;class_declaration=(funthis->CE.class_infosthis(this.class_exprthis));class_expr=CE.map;class_field=CE.map_field;class_structure=CE.map_structure;class_type=CT.map;class_type_field=CT.map_field;class_signature=CT.map_signature;class_type_declaration=(funthis->CE.class_infosthis(this.class_typethis));class_description=(funthis->CE.class_infosthis(this.class_typethis));type_declaration=T.map_type_declaration;type_kind=T.map_type_kind;typ=T.map;type_extension=T.map_type_extension;extension_constructor=T.map_extension_constructor;value_description=(funthis{pval_name;pval_type;pval_prim;pval_loc;pval_attributes}->Val.mk(map_locthispval_name)(this.typthispval_type)~attrs:(this.attributesthispval_attributes)~loc:(this.locationthispval_loc)~prim:pval_prim);pat=P.map;expr=E.map;module_declaration=(funthis{pmd_name;pmd_type;pmd_attributes;pmd_loc}->Md.mk(map_locthispmd_name)(this.module_typethispmd_type)~attrs:(this.attributesthispmd_attributes)~loc:(this.locationthispmd_loc));module_type_declaration=(funthis{pmtd_name;pmtd_type;pmtd_attributes;pmtd_loc}->Mtd.mk(map_locthispmtd_name)?typ:(map_opt(this.module_typethis)pmtd_type)~attrs:(this.attributesthispmtd_attributes)~loc:(this.locationthispmtd_loc));module_binding=(funthis{pmb_name;pmb_expr;pmb_attributes;pmb_loc}->Mb.mk(map_locthispmb_name)(this.module_exprthispmb_expr)~attrs:(this.attributesthispmb_attributes)~loc:(this.locationthispmb_loc));open_description=(funthis{popen_lid;popen_override;popen_attributes;popen_loc}->Opn.mk(map_locthispopen_lid)~override:popen_override~loc:(this.locationthispopen_loc)~attrs:(this.attributesthispopen_attributes));include_description=(funthis{pincl_mod;pincl_attributes;pincl_loc}->Incl.mk(this.module_typethispincl_mod)~loc:(this.locationthispincl_loc)~attrs:(this.attributesthispincl_attributes));include_declaration=(funthis{pincl_mod;pincl_attributes;pincl_loc}->Incl.mk(this.module_exprthispincl_mod)~loc:(this.locationthispincl_loc)~attrs:(this.attributesthispincl_attributes));value_binding=(funthis{pvb_pat;pvb_expr;pvb_attributes;pvb_loc}->Vb.mk(this.patthispvb_pat)(this.exprthispvb_expr)~loc:(this.locationthispvb_loc)~attrs:(this.attributesthispvb_attributes));constructor_declaration=(funthis{pcd_name;pcd_args;pcd_res;pcd_loc;pcd_attributes}->Type.constructor(map_locthispcd_name)~args:(T.map_constructor_argumentsthispcd_args)?res:(map_opt(this.typthis)pcd_res)~loc:(this.locationthispcd_loc)~attrs:(this.attributesthispcd_attributes));label_declaration=(funthis{pld_name;pld_type;pld_loc;pld_mutable;pld_attributes}->Type.field(map_locthispld_name)(this.typthispld_type)~mut:pld_mutable~loc:(this.locationthispld_loc)~attrs:(this.attributesthispld_attributes));cases=(funthisl->List.map(this.casethis)l);case=(funthis{pc_lhs;pc_guard;pc_rhs}->{pc_lhs=this.patthispc_lhs;pc_guard=map_opt(this.exprthis)pc_guard;pc_rhs=this.exprthispc_rhs;});location=(fun_thisl->l);extension=(funthis(s,e)->(map_locthiss,this.payloadthise));attribute=(funthis(s,e)->(map_locthiss,this.payloadthise));attributes=(funthisl->List.map(this.attributethis)l);payload=(funthis->function|PStrx->PStr(this.structurethisx)|PSigx->PSig(this.signaturethisx)|PTypx->PTyp(this.typthisx)|PPat(x,g)->PPat(this.patthisx,map_opt(this.exprthis)g));}letextension_of_error(error:Locations.location_error):extension=Locations.extension_of_error~mk_pstr:(function|x::l->PStr(x::x::l)|l->PStrl)~mk_extension:(funx->Str.extensionx)~mk_string_constant:(funx->Str.eval(Exp.constant(Pconst_string(x,None))))errorletattribute_of_warninglocs={loc;txt="ocaml.ppwarning"},PStr([Str.eval~loc(Exp.constant(Pconst_string(s,None)))])includeLocations.Helpers_implendmoduleOutcometree=struct(* Module [Outcometree]: results displayed by the toplevel *)(* These types represent messages that the toplevel displays as normal
results or errors. The real displaying is customisable using the hooks:
[Toploop.print_out_value]
[Toploop.print_out_type]
[Toploop.print_out_sig_item]
[Toploop.print_out_phrase] *)typeout_ident(*IF_CURRENT = Outcometree.out_ident *)=|Oide_applyofout_ident*out_ident|Oide_dotofout_ident*string|Oide_identofstringtypeout_string(*IF_CURRENT = Outcometree.out_string *)=|Ostr_string|Ostr_bytestypeout_attribute(*IF_CURRENT = Outcometree.out_attribute *)={oattr_name:string}typeout_value(*IF_CURRENT = Outcometree.out_value *)=|Oval_arrayofout_valuelist|Oval_charofchar|Oval_constrofout_ident*out_valuelist|Oval_ellipsis|Oval_floatoffloat|Oval_intofint|Oval_int32ofint32|Oval_int64ofint64|Oval_nativeintofnativeint|Oval_listofout_valuelist|Oval_printerof(Format.formatter->unit)|Oval_recordof(out_ident*out_value)list|Oval_stringofstring*int*out_string(* string, size-to-print, kind *)|Oval_stuffofstring|Oval_tupleofout_valuelist|Oval_variantofstring*out_valueoptiontypeout_type(*IF_CURRENT = Outcometree.out_type *)=|Otyp_abstract|Otyp_open|Otyp_aliasofout_type*string|Otyp_arrowofstring*out_type*out_type|Otyp_classofbool*out_ident*out_typelist|Otyp_constrofout_ident*out_typelist|Otyp_manifestofout_type*out_type|Otyp_objectof(string*out_type)list*booloption|Otyp_recordof(string*bool*out_type)list|Otyp_stuffofstring|Otyp_sumof(string*out_typelist*out_typeoption)list|Otyp_tupleofout_typelist|Otyp_varofbool*string|Otyp_variantofbool*out_variant*bool*(stringlist)option|Otyp_polyofstringlist*out_type|Otyp_moduleofstring*stringlist*out_typelist|Otyp_attributeofout_type*out_attributeandout_variant(*IF_CURRENT = Outcometree.out_variant *)=|Ovar_fieldsof(string*bool*out_typelist)list|Ovar_typofout_typetypeout_class_type(*IF_CURRENT = Outcometree.out_class_type *)=|Octy_constrofout_ident*out_typelist|Octy_arrowofstring*out_type*out_class_type|Octy_signatureofout_typeoption*out_class_sig_itemlistandout_class_sig_item(*IF_CURRENT = Outcometree.out_class_sig_item *)=|Ocsg_constraintofout_type*out_type|Ocsg_methodofstring*bool*bool*out_type|Ocsg_valueofstring*bool*bool*out_typetypeout_module_type(*IF_CURRENT = Outcometree.out_module_type *)=|Omty_abstract|Omty_functorofstring*out_module_typeoption*out_module_type|Omty_identofout_ident|Omty_signatureofout_sig_itemlist|Omty_aliasofout_identandout_sig_item(*IF_CURRENT = Outcometree.out_sig_item *)=|Osig_classofbool*string*(string*(bool*bool))list*out_class_type*out_rec_status|Osig_class_typeofbool*string*(string*(bool*bool))list*out_class_type*out_rec_status|Osig_typextofout_extension_constructor*out_ext_status|Osig_modtypeofstring*out_module_type|Osig_moduleofstring*out_module_type*out_rec_status|Osig_typeofout_type_decl*out_rec_status|Osig_valueofout_val_decl|Osig_ellipsisandout_type_decl(*IF_CURRENT = Outcometree.out_type_decl *)={otype_name:string;otype_params:(string*(bool*bool))list;otype_type:out_type;otype_private:Asttypes.private_flag;otype_immediate:bool;otype_unboxed:bool;otype_cstrs:(out_type*out_type)list}andout_extension_constructor(*IF_CURRENT = Outcometree.out_extension_constructor *)={oext_name:string;oext_type_name:string;oext_type_params:stringlist;oext_args:out_typelist;oext_ret_type:out_typeoption;oext_private:Asttypes.private_flag}andout_type_extension(*IF_CURRENT = Outcometree.out_type_extension *)={otyext_name:string;otyext_params:stringlist;otyext_constructors:(string*out_typelist*out_typeoption)list;otyext_private:Asttypes.private_flag}andout_val_decl(*IF_CURRENT = Outcometree.out_val_decl *)={oval_name:string;oval_type:out_type;oval_prims:stringlist;oval_attributes:out_attributelist}andout_rec_status(*IF_CURRENT = Outcometree.out_rec_status *)=|Orec_not|Orec_first|Orec_nextandout_ext_status(*IF_CURRENT = Outcometree.out_ext_status *)=|Oext_first|Oext_next|Oext_exceptiontypeout_phrase(*IF_CURRENT = Outcometree.out_phrase *)=|Ophr_evalofout_value*out_type|Ophr_signatureof(out_sig_item*out_valueoption)list|Ophr_exceptionof(exn*out_value)endmoduleConfig=structletast_impl_magic_number="Caml1999M022"letast_intf_magic_number="Caml1999N022"endletmap_signaturemapper=mapper.Ast_mapper.signaturemapperletmap_structuremapper=mapper.Ast_mapper.structuremapperletshallow_identity=letid_x=xin{Ast_mapper.structure=id;structure_item=id;module_expr=id;signature=id;signature_item=id;module_type=id;with_constraint=id;class_declaration=id;class_expr=id;class_field=id;class_structure=id;class_type=id;class_type_field=id;class_signature=id;class_type_declaration=id;class_description=id;type_declaration=id;type_kind=id;typ=id;type_extension=id;extension_constructor=id;value_description=id;pat=id;expr=id;module_declaration=id;module_type_declaration=id;module_binding=id;open_description=id;include_description=id;include_declaration=id;value_binding=id;constructor_declaration=id;label_declaration=id;cases=id;case=id;location=id;extension=id;attribute=id;attributes=id;payload=id;}letfailing_mapper=letfail__=invalid_arg"failing_mapper: this mapper function should never get called"in{Ast_mapper.structure=fail;structure_item=fail;module_expr=fail;signature=fail;signature_item=fail;module_type=fail;with_constraint=fail;class_declaration=fail;class_expr=fail;class_field=fail;class_structure=fail;class_type=fail;class_type_field=fail;class_signature=fail;class_type_declaration=fail;class_description=fail;type_declaration=fail;type_kind=fail;typ=fail;type_extension=fail;extension_constructor=fail;value_description=fail;pat=fail;expr=fail;module_declaration=fail;module_type_declaration=fail;module_binding=fail;open_description=fail;include_description=fail;include_declaration=fail;value_binding=fail;constructor_declaration=fail;label_declaration=fail;cases=fail;case=fail;location=fail;extension=fail;attribute=fail;attributes=fail;payload=fail;}letmake_top_mapper~signature~structure={failing_mapperwithAst_mapper.signature=(fun_x->signaturex);structure=(fun_x->structurex)}