123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(************************************************************************)(* * The Rocq Prover / The Rocq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openUtilopenPpopenGenargopenLocusletbeautify_comments=ref[]letrecsplit_commentscomaccaccpos=function|[]->beautify_comments:=List.revacc;comacc|((b,e),cascom)::coms->(* Take all comments that terminates before pos, or begin exactly
at pos (used to print comments attached after an expression) *)ife<=pos||pos=bthensplit_comments(c::comacc)accposcomselsesplit_commentscomacc(com::acc)poscomsletextract_commentspos=split_comments[][]pos!beautify_commentsletpr_locatedpr(loc,x)=matchlocwith|Somelocwhen!Flags.beautify->let(b,e)=Loc.unloclocin(* Side-effect: order matters *)letbefore=Pp.comment(extract_commentsb)inletx=prxinletafter=Pp.comment(extract_commentse)inbefore++x++after|_->prxletpr_astpr{CAst.loc;v}=pr_locatedpr(loc,v)letpr_lident{CAst.loc;v=id}=letopenNames.Idinmatchlocwith|None->printid|Someloc->let(b,_)=Loc.unloclocinpr_locatedprint(Some(Loc.make_loc(b,b+String.length(to_stringid))),id)letpr_lname=letopenNamesinfunction|{CAst.loc;v=Nameid}->pr_lidentCAst.(make?locid)|x->pr_astName.printxletpr_or_varpr=function|ArgArgx->prx|ArgVarid->pr_lidentidletpr_or_by_notationf=letopenConstrexprinCAst.with_val(function|ANv->fv|ByNotation(s,sc)->qss++pr_opt(funsc->str"%"++strsc)sc)lethov_if_not_emptynp=ifPp.ismtpthenpelsehovnpletrecpr_raw_genericenvsigma(GenArg(Rawwitwit,x))=matchwitwith|ListArgwit->letmapx=pr_raw_genericenvsigma(in_gen(rawwitwit)x)inletans=pr_sequencemapxinhov_if_not_empty0ans|OptArgwit->letans=matchxwith|None->mt()|Somex->pr_raw_genericenvsigma(in_gen(rawwitwit)x)inhov_if_not_empty0ans|PairArg(wit1,wit2)->letp,q=xinletp=in_gen(rawwitwit1)pinletq=in_gen(rawwitwit2)qinhov_if_not_empty0(pr_sequence(pr_raw_genericenvsigma)[p;q])|ExtraArgs->letopenGenprintinmatchgeneric_raw_print(in_gen(rawwitwit)x)with|PrinterBasicpp->ppenvsigma|PrinterNeedsLevel{default_ensure_surrounded;printer}->printerenvsigmadefault_ensure_surroundedletrecpr_glb_genericenvsigma(GenArg(Glbwitwit,x))=matchwitwith|ListArgwit->letmapx=pr_glb_genericenvsigma(in_gen(glbwitwit)x)inletans=pr_sequencemapxinhov_if_not_empty0ans|OptArgwit->letans=matchxwith|None->mt()|Somex->pr_glb_genericenvsigma(in_gen(glbwitwit)x)inhov_if_not_empty0ans|PairArg(wit1,wit2)->letp,q=xinletp=in_gen(glbwitwit1)pinletq=in_gen(glbwitwit2)qinletans=pr_sequence(pr_glb_genericenvsigma)[p;q]inhov_if_not_empty0ans|ExtraArgs->letopenGenprintinmatchgeneric_glb_print(in_gen(glbwitwit)x)with|PrinterBasicpp->ppenvsigma|PrinterNeedsLevel{default_ensure_surrounded;printer}->printerenvsigmadefault_ensure_surrounded