123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254(**************************************************************************
* Copyright (C) 2005-2021
* Dmitri Boulytchev (db@tepkom.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).
**************************************************************************)openPrintftypeer=Buffer.t->unittypeviewer=erlettoStringv=letb=Buffer.create1024invb;Buffer.contentsbletemptyb=()letconcatxyb=xb;ybletstringxb=Buffer.add_stringbxletunit_=string"()"letintx=string(string_of_intx)letfloatx=string(string_of_floatx)letboolx=string(string_of_boolx)letcharx=string(Printf.sprintf"%c"x)letsemicolon=string"; "letcomma=string", "letspace=string" "letbreak=string"\n"letseqvb=List.iter(funx->xb)vletseqavb=Array.iter(funx->xb)vletlistBydvb=ignore(List.fold_left(funlx->xb;matchlwith[]->[]|hd::tl->db;tl)(matchvwith[]->[]|_::tl->tl)v)letlist=listBycommaletarrayBydvb=letn=Array.lengthvinArray.iteri(funix->xb;ifi<n-1thendb)vletarray=arrayBycommaletinbrlrb=seq[l;b;r]letinrbrb=inbr(string"(")(string")")bletinsqbrb=inbr(string"[")(string"]")bletincvbrb=inbr(string"{")(string"}")bletconcatWithDelimiterdelimiteraccx=matchaccwith""->x|_->acc^delimiter^xletconcatWithComma=concatWithDelimiter", "letconcatWithSemicolon=concatWithDelimiter"; "moduletypeViewable=sigtypetvaltoString:t->stringendmoduletypeConcat=sigvalconcat:string->string->stringendmoduleL=ListopenListmoduleListC(C:Concat)(X:Viewable)=structtypet=X.tlistlettoString=fold_left(funaccx->C.concatacc(X.toStringx))""endmoduleList=ListC(structletconcat=concatWithCommaend)openArraymoduleArrayC(C:Concat)(X:Viewable)=structtypet=X.tarraylettoString=fold_left(funaccx->C.concatacc(X.toStringx))""endmoduleArray=ArrayC(structletconcat=concatWithCommaend)moduleSetC(C:Concat)(S:Set.S)(V:Viewablewithtypet=S.elt)=structtypet=S.tlettoStringx=letmoduleX=ListC(C)(V)inX.toString(S.elementsx)endmoduleSet=SetC(structletconcat=concatWithCommaend)moduleNamedPair(N:sigvalfirst:stringvalsecond:stringend)(F:Viewable)(S:Viewable)=structtypet=F.t*S.tlettoString(x,y)=letfieldvalue=function""->value|name->sprintf"%s=%s"namevalueinsprintf"(%s, %s)"(field(F.toStringx)N.first)(field(S.toStringy)N.second)endmodulePair=NamedPair(structletfirst=""letsecond=""end)moduleChar=structtypet=charlettoString=String.make1endmoduleString=structtypet=stringlettoStringx=xendmoduleMapC(C:Concat)(M:Map.S)(K:Viewablewithtypet=M.key)(V:Viewable)=structtypet=V.tM.tlettoStringx=letmoduleP=Pair(K)(V)inletmoduleX=ListC(C)(String)inX.toString(L.sortStdlib.compare(M.fold(funxyacc->(P.toString(x,y))::acc)x[]))endmoduleMap=MapC(structletconcat=concatWithCommaend)moduleHashtblC(C:Concat)(M:Hashtbl.S)(K:Viewablewithtypet=M.key)(V:Viewable)=structtypet=V.tM.tlettoStringx=letmoduleP=Pair(K)(V)inletmoduleX=ListC(C)(String)inX.toString(L.sortStdlib.compare(M.fold(funxyacc->(P.toString(x,y))::acc)x[]))endmoduleHashtbl=HashtblC(structletconcat=concatWithCommaend)moduleInteger=structtypet=intlettoString=string_of_intendmoduleFloat=structtypet=floatlettoString=string_of_floatendmoduleBool=structtypet=boollettoString=string_of_boolendmoduleExn=structtypet=exnlettoString=Printexc.to_stringendmoduleUnit=structtypet=unitlettoString_="()"endmoduleInt32=structtypet=int32lettoString=Int32.to_stringendmoduleInt64=structtypet=int64lettoString=Int64.to_stringendmoduleNativeint=structtypet=nativeintlettoString=Nativeint.to_stringend