123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105(************************************************************************)(* * The Coq Proof Assistant / The Coq 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) *)(************************************************************************)openUtilopenPpopenCErrorsopenNotationopenConstrexpr(*s Pretty-print. *)typeppbox=|PpHB|PpHOVBofint|PpHVBofint|PpVBofinttypeppcut=|PpBrkofint*int|PpFnlletppcmd_of_box=function|PpHB->h|PpHOVBn->hovn|PpHVBn->hvn|PpVBn->vnletppcmd_of_cut=function|PpFnl->fnl()|PpBrk(n1,n2)->brk(n1,n2)typepattern_quote_style=QuotedPattern|NotQuotedPatterntypeunparsing=|UnpMetaVarofentry_relative_level*Extend.sideoption|UnpBinderMetaVarofentry_relative_level*pattern_quote_style|UnpListMetaVarofentry_relative_level*unparsinglist*Extend.sideoption|UnpBinderListMetaVarofbool*unparsinglist|UnpTerminalofstring|UnpBoxofppbox*unparsingLoc.locatedlist|UnpCutofppcuttypeunparsing_rule=unparsinglist*entry_leveltypeextra_unparsing_rules=(string*string)listletrecunparsing_equnp1unp2=match(unp1,unp2)with|UnpMetaVar(p1,s1),UnpMetaVar(p2,s2)->entry_relative_level_eqp1p2&&s1=s2|UnpBinderMetaVar(p1,s1),UnpBinderMetaVar(p2,s2)->entry_relative_level_eqp1p2&&s1=s2|UnpListMetaVar(p1,l1,s1),UnpListMetaVar(p2,l2,s2)->entry_relative_level_eqp1p2&&List.for_all2equnparsing_eql1l2&&s1=s2|UnpBinderListMetaVar(b1,l1),UnpBinderListMetaVar(b2,l2)->b1=b2&&List.for_all2equnparsing_eql1l2|UnpTerminals1,UnpTerminals2->String.equals1s2|UnpBox(b1,l1),UnpBox(b2,l2)->b1=b2&&List.for_all2equnparsing_eq(List.mapsndl1)(List.mapsndl2)|UnpCutp1,UnpCutp2->p1=p2|(UnpMetaVar_|UnpBinderMetaVar_|UnpListMetaVar_|UnpBinderListMetaVar_|UnpTerminal_|UnpBox_|UnpCut_),_->false(* Register generic and specific printing rules *)letgeneric_notation_printing_rules=Summary.ref~name:"generic-notation-printing-rules"(NotationMap.empty:(unparsing_rule*bool*extra_unparsing_rules)NotationMap.t)letspecific_notation_printing_rules=Summary.ref~name:"specific-notation-printing-rules"(SpecificNotationMap.empty:(unparsing_rule*extra_unparsing_rules)SpecificNotationMap.t)letdeclare_generic_notation_printing_rulesntn~reserved~extraunpl=generic_notation_printing_rules:=NotationMap.addntn(unpl,reserved,extra)!generic_notation_printing_rulesletdeclare_specific_notation_printing_rulesspecific_ntn~extraunpl=specific_notation_printing_rules:=SpecificNotationMap.addspecific_ntn(unpl,extra)!specific_notation_printing_ruleslethas_generic_notation_printing_rulentn=NotationMap.memntn!generic_notation_printing_rulesletfind_generic_notation_printing_rulentn=NotationMap.findntn!generic_notation_printing_rulesletfind_specific_notation_printing_rulespecific_ntn=SpecificNotationMap.findspecific_ntn!specific_notation_printing_rulesletfind_notation_printing_rulewhichntn=trymatchwhichwith|None->raiseNot_found(* Normally not the case *)|Somewhich->fst(find_specific_notation_printing_rule(which,ntn))withNot_found->pi1(find_generic_notation_printing_rulentn)letfind_notation_extra_printing_ruleswhichntn=trymatchwhichwith|None->raiseNot_found|Somewhich->snd(find_specific_notation_printing_rule(which,ntn))withNot_found->pi3(find_generic_notation_printing_rulentn)letadd_notation_extra_printing_rulentnkv=trygeneric_notation_printing_rules:=letp,b,pp=NotationMap.findntn!generic_notation_printing_rulesinNotationMap.addntn(p,b,(k,v)::pp)!generic_notation_printing_ruleswithNot_found->user_err~hdr:"add_notation_extra_printing_rule"(str"No such Notation.")