123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128(*
* Pretty: basic set of pretty-printing combinators.
* Copyright (C) 2006-2008
* Dmitri Boulytchev, St.Petersburg State University
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2, as published by the Free Software Foundation.
*
* This software 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 Library General Public License version 2 for more details
* (enclosed in the file COPYING).
*)openFormattypeprinter=formatter->unitlettoStringp=letbuf=Buffer.create1024inletppf=formatter_of_bufferbufinpppf;pp_print_flushppf();Buffer.contentsbufletempty_ppf=()letnewlineppf=fprintfppf"@\n"letbreakppf=fprintfppf"@,"letboxppf=fprintfppf"@["letvboxppf=fprintfppf"@[<v 0>"lethboxppf=fprintfppf"@[<h 0>"lethovboxppf=fprintfppf"@[<hov 0>"lethvboxppf=fprintfppf"@[<hv 0>"letendboxppf=fprintfppf"@]"letstringstr=funppf->fprintfppf"%s"strletintint=funppf->fprintfppf"%d"intletcharchar=funppf->fprintfppf"%c"charletboolbool=funppf->fprintfppf"%b"boolletfloatfloat=funppf->fprintfppf"%f"floatletseqelems=funppf->List.iter(fune->eppf)elemsletseqaelems=funppf->Array.iter(fune->eppf)elemsletlistBydelimlist=funppf->ignore(List.fold_left(funflage->ifflag&&(e!=empty)thendelimppf;eppf;true)falselist)letlistAllBydelimlist=funppf->ignore(List.fold_left(funflage->ifflagthendelimppf;eppf;true)falselist)letarrayBydelima=funppf->letl=Array.lengtha-1infori=0toldoifi>0&&(a.(i)!=empty)thendelimppf;a.(i)ppfdoneletarrayAllBydelima=funppf->letl=Array.lengtha-1infori=0toldoifi>0thendelimppf;a.(i)ppfdoneletlistBySemicolon:printerlist->printer=listBy(string"; ")letlistByComma:printerlist->printer=listBy(string", ")letlistBySpace:printerlist->printer=listBy(string" ")letlistBySemicolonBreak:printerlist->printer=listBy(seq[string"; ";break])letlistByCommaBreak:printerlist->printer=listBy(seq[string", ";break])letlistBySpaceBreak:printerlist->printer=listBy(seq[string" ";break])letlistByBreak:printerlist->printer=listBybreakletarrayBySemicolon:printerarray->printer=arrayBy(string"; ")letarrayByComma:printerarray->printer=arrayBy(string", ")letarrayBySpace:printerarray->printer=arrayBy(string" ")letarrayBySemicolonBreak:printerarray->printer=arrayBy(seq[string"; ";break])letarrayByCommaBreak:printerarray->printer=arrayBy(seq[string", ";break])letarrayBySpaceBreak:printerarray->printer=arrayBy(seq[string" ";break])letarrayByBreak:printerarray->printer=arrayBybreakletencloseboxp=funppf->seq[box;p;endbox]ppfletpad=string" "letboxed=encloseboxlethboxed=enclosehboxletvboxed=enclosevboxlethovboxed=enclosehovboxlethvboxed=enclosehvboxletblockocb=vboxed(seq[o;break;pad;b;break;c])letplockpb=vboxed(seq[p;break;pad;b])letbrboxedocb=hboxed(seq[o;break;b;break;c])letrboxed=brboxed(string"(")(string")")letsboxed=brboxed(string"[")(string"]")letcboxed=brboxed(string"{")(string"}")