123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131(**************************************************************************
* Copyright (C) 2012-2020
* Dmitri Boulytchev (dboulytchev@math.spbu.ru), St.Petersburg State University
* Universitetskii pr., 28, St.Petersburg, 198504, RUSSIA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* See the GNU Lesser General Public License version 2.1 for more details
* (enclosed in the file COPYING).
**************************************************************************)openPcamlopenGTCommonlethdtllocxs=(List.hdxs,List.tlxs)lettrait_proto_ttyptrait=Printf.sprintf"%s_proto_%s"traittypEXTENDGLOBAL:sig_itemstr_itemclass_exprclass_sig_itemexprctyptype_declclass_expr_simpleextended_longident;class_sig_item:[["inherit";cs=class_signature-><:class_sig_item<inherit$cs$>>]];class_signature:[[ci=class_type_longident->letlast,pfx=Camlp5Helpers.sep_lastciinassert(not(Camlp5Helpers.capitalizedlast));matchpfxwith[]-><:class_type<$lid:last$>>|h::t->letreclirecli=functionh::t->lirec<:extended_longident<$longid:li$.$uid:h$>>t|[]->liinletli=lirec<:extended_longident<$uid:h$>>tin<:class_type<$longid:li$.$lid:last$>>]];class_type_longident:[["@";ci=qname;t=OPTtrait->letn,q=hdtlloc(List.revci)inletclassname=matchtwith|None->Naming.class_name_for_typn|Somet->Naming.trait_class_name_for_typ~trait:tninList.rev(classname::q)|"+";ci=qname;t=trait->letn,q=hdtlloc(List.revci)inList.rev((trait_proto_ttn)::q)]];class_expr_simple:BEFORE"simple"[["[";ct=ctyp;",";ctcl=LIST1ctypSEP",";"]";ci=class_longident-><:class_expr<[$list:(ct::ctcl)$]$lilongid:ci$>>|"[";ct=ctyp;"]";ci=class_longident-><:class_expr<[$ct$]$lilongid:ci$>>|ci=class_longident-><:class_expr<$lilongid:ci$>>]];expr:BEFORE"simple"[LEFTA["new";i=Vclass_longident"list"-><:expr<new$_lilongid:i$>>]];ctyp:BEFORE"simple"[["#";id=Vclass_longident"list"-><:ctyp<#$_lilongid:id$>>]];class_longident:[["@";ci=qname;t=OPTtrait->letn,q=hdtlloc(List.revci)inletclassname=matchtwith|None->Naming.class_name_for_typn|Somet->Naming.trait_class_name_for_typ~trait:tninAsttools.longident_lident_of_string_listloc(List.rev(classname::q))|"+";ci=qname;t=trait->letn,q=hdtlloc(List.revci)inAsttools.longident_lident_of_string_listloc(List.rev((trait_proto_tnt)::q))|ci=qname->Asttools.longident_lident_of_string_listlocci]];qname:[[n=LIDENT->[n]|m=UIDENT;".";q=SELF->m::q]];trait:[["[";id=LIDENT;"]"->id]];nonrec_:[["nonrec"->()]];str_item:LEVEL"top"[["@";"type";nonrec_=(OPTnonrec_);t=LIST1t_declSEP"and"->Core2.generate_str(Option.is_somenonrec_)tloc]];sig_item:LEVEL"top"[["@";"type";nonrec_=(OPTnonrec_);t=LIST1t_declSEP"and"->Core2.generate_sig(Option.is_somenonrec_)tloc]];t_decl:[["[";t=type_decl;"]"->t,[]|t=type_decl;d=OPTderiving->(* t, [tdecl_to_descr loc t, match d with None -> [] | Some d -> d] *)t,(matchdwithNone->[]|Somed->d)]];deriving:[["with";s=LIST1LIDENTSEP","->s]];END;