123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288(************************************************************************)(* * 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) *)(************************************************************************)(** Declaration of uninterpretation functions (i.e. printing rules)
for notations *)(*i*)openUtilopenNamesopenGlobnamesopenConstrexpropenNotation_termopenGlob_term(*i*)letnotation_with_optional_scope_eqinscope1inscope2=match(inscope1,inscope2)with|LastLonelyNotation,LastLonelyNotation->true|NotationInScopes1,NotationInScopes2->String.equals1s2|(LastLonelyNotation|NotationInScope_),_->falseletentry_relative_level_eqt1t2=matcht1,t2with|LevelLtn1,LevelLtn2->Int.equaln1n2|LevelLen1,LevelLen2->Int.equaln1n2|LevelSome,LevelSome->true|(LevelLt_|LevelLe_|LevelSome),_->falseletnotation_entry_eqs1s2=match(s1,s2)with|InConstrEntry,InConstrEntry->true|InCustomEntrys1,InCustomEntrys2->String.equals1s2|(InConstrEntry|InCustomEntry_),_->falseletnotation_entry_level_eq{notation_entry=e1;notation_level=n1}{notation_entry=e2;notation_level=n2}=notation_entry_eqe1e2&&Int.equaln1n2letnotation_entry_relative_level_eq{notation_subentry=e1;notation_relative_level=n1;notation_position=s1}{notation_subentry=e2;notation_relative_level=n2;notation_position=s2}=notation_entry_eqe1e2&&entry_relative_level_eqn1n2&&s1=s2letnotation_eq(from1,ntn1)(from2,ntn2)=notation_entry_eqfrom1from2&&String.equalntn1ntn2letpair_eqfg(x1,y1)(x2,y2)=fx1x2&&gy1y2letnotation_binder_kind_eqk1k2=matchk1,k2with|AsIdent,AsIdent->true|AsName,AsName->true|AsAnyPattern,AsAnyPattern->true|AsStrictPattern,AsStrictPattern->true|(AsIdent|AsName|AsAnyPattern|AsStrictPattern),_->falseletnotation_binder_source_eqs1s2=matchs1,s2with|NtnBinderParsedAsSomeBinderKindbk1,NtnBinderParsedAsSomeBinderKindbk2->notation_binder_kind_eqbk1bk2|NtnBinderParsedAsBinder,NtnBinderParsedAsBinder->true|NtnBinderParsedAsConstrbk1,NtnBinderParsedAsConstrbk2->notation_binder_kind_eqbk1bk2|(NtnBinderParsedAsSomeBinderKind_|NtnBinderParsedAsBinder|NtnBinderParsedAsConstr_),_->falseletntpe_eqt1t2=matcht1,t2with|NtnTypeConstr,NtnTypeConstr->true|NtnTypeBinders1,NtnTypeBinders2->notation_binder_source_eqs1s2|NtnTypeConstrList,NtnTypeConstrList->true|NtnTypeBinderLists1,NtnTypeBinderLists2->notation_binder_source_eqs1s2|(NtnTypeConstr|NtnTypeBinder_|NtnTypeConstrList|NtnTypeBinderList_),_->falseletvar_attributes_eq(_,((entry1,sc1),binders1,tp1))(_,((entry2,sc2),binders2,tp2))=notation_entry_relative_level_eqentry1entry2&&pair_eq(List.equalString.equal)(List.equalString.equal)sc1sc2&&Id.Set.equalbinders1binders2&&ntpe_eqtp1tp2letinterpretation_eq(vars1,t1asx1)(vars2,t2asx2)=x1==x2||List.equalvar_attributes_eqvars1vars2&&Notation_ops.eq_notation_constr(List.mapfstvars1,List.mapfstvars2)t1t2typelevel=notation_entry_level*entry_relative_levellistletlevel_eq({notation_entry=s1;notation_level=l1},t1)({notation_entry=s2;notation_level=l2},t2)=notation_entry_eqs1s2&&Int.equall1l2&&List.equalentry_relative_level_eqt1t2(** Uninterpretation tables *)type'ainterp_rule_gen=|NotationRuleofConstrexpr.specific_notation|AbbrevRuleof'atypeinterp_rule=KerName.tinterp_rule_genletspecific_notation_eq(sc1,(e1,s1))(sc2,(e2,s2))=notation_with_optional_scope_eqsc1sc2&¬ation_entry_eqe1e2&&String.equals1s2letinterp_rule_eqr1r2=matchr1,r2with|NotationRulen1,NotationRulen2->specific_notation_eqn1n2|AbbrevRulekn1,AbbrevRulekn2->KerName.equalkn1kn2|(AbbrevRule_|NotationRule_),_->false(* We define keys for glob_constr and aconstr to split the syntax entries
according to the key of the pattern (adapted from Chet Murthy by HH) *)typekey=|RefKeyofGlobRef.t|Othletkey_comparek1k2=matchk1,k2with|RefKeygr1,RefKeygr2->GlobRef.CanOrd.comparegr1gr2|RefKey_,Oth->-1|Oth,RefKey_->1|Oth,Oth->0moduleKeyOrd=structtypet=keyletcompare=key_compareendmoduleKeyMap=Map.Make(KeyOrd)typenotation_applicative_status=|AppBoundedNotationofint|AppUnboundedNotation|NotAppNotationletnotation_applicative_status_eqs1s2=matchs1,s2with|AppBoundedNotationn1,AppBoundedNotationn2->Int.equaln1n2|AppUnboundedNotation,AppUnboundedNotation->true|NotAppNotation,NotAppNotation->true|(AppBoundedNotation_|AppUnboundedNotation|NotAppNotation),_->falsetypenotation_rule={not_rule:interp_rule;not_patt:interpretation;not_status:notation_applicative_status;}letnotation_rule_eqx1x2=x1==x2||(interp_rule_eqx1.not_rulex2.not_rule&&interpretation_eqx1.not_pattx2.not_patt&¬ation_applicative_status_eqx1.not_statusx2.not_status)moduleNotationSet:sigtypetvalempty:tvaladd:notation_rule->t->tvalremove:notation_rule->t->tvalrepr:t->notation_rulelistend=structtypediff=Add|Subtypedata={ntn_todo:(diff*notation_rule)list;ntn_done:notation_rulelist;}typet=datarefoptionletempty=Noneletpushkrs=matchswith|None->Some(ref{ntn_done=[];ntn_todo=[k,r]})|Some{contents=s}->Some(ref{ntn_done=s.ntn_done;ntn_todo=(k,r)::s.ntn_todo})letaddrs=pushAddrsletremovers=pushSubrsletforces=ifList.is_emptys.ntn_todothenNoneelseletcmpr1r2=Notation_ops.strictly_finer_interpretation_thanr1.not_pattr2.not_pattin(* strictly finer interpretation are kept in front *)letfoldaccu(knd,ntn)=matchkndwith|Add->letfiner,rest=List.partition(func->cmpcntn)accuin(finer@ntn::rest)|Sub->List.remove_first(funrule->notation_rule_eqntnrule)accuinSome(List.fold_leftfolds.ntn_done(List.revs.ntn_todo))letreprs=matchswith|None->[]|Somer->matchforce!rwith|None->r.contents.ntn_done|Someans->let()=r:={ntn_done=ans;ntn_todo=[]}inansendletkeymap_addkeyinterpmap=letold=tryKeyMap.findkeymapwithNot_found->NotationSet.emptyinKeyMap.addkey(NotationSet.addinterpold)mapletkeymap_removekeyinterpmap=letold=tryKeyMap.findkeymapwithNot_found->NotationSet.emptyinKeyMap.addkey(NotationSet.removeinterpold)mapletkeymap_findkeymap=tryNotationSet.repr(KeyMap.findkeymap)withNot_found->[](* Scopes table : interpretation -> scope_name *)letnotations_key_table=Summary.ref~stage:Summary.Stage.Interp~name:"notation_uninterpretation"(KeyMap.empty:NotationSet.tKeyMap.t)letglob_constr_keysc=matchDAst.getcwith|GApp(c,_)->beginmatchDAst.getcwith|GRef(ref,_)->[RefKey(canonical_grref);Oth]|_->[Oth]end|GProj((cst,_),_,_)->[RefKey(canonical_gr(GlobRef.ConstRefcst))]|GRef(ref,_)->[RefKey(canonical_grref)]|_->[Oth]letcases_pattern_keyc=matchDAst.getcwith|PatCstr(ref,_,_)->RefKey(canonical_gr(GlobRef.ConstructRefref))|_->Othletnotation_constr_key=function(* Rem: NApp(NRef ref,[]) stands for @ref *)|NApp(NRef(ref,_),args)->RefKey(canonical_grref),AppBoundedNotation(List.lengthargs)|NProj((cst,_),args,_)->RefKey(canonical_gr(GlobRef.ConstRefcst)),AppBoundedNotation(List.lengthargs+1)|NList(_,_,NApp(NRef(ref,_),args),_,_)|NBinderList(_,_,NApp(NRef(ref,_),args),_,_)->RefKey(canonical_grref),AppBoundedNotation(List.lengthargs)|NRef(ref,_)->RefKey(canonical_grref),NotAppNotation|NApp(NList(_,_,NApp(NRef(ref,_),args),_,_),args')->RefKey(canonical_grref),AppBoundedNotation(List.lengthargs+List.lengthargs')|NApp(NList(_,_,NApp(_,args),_,_),args')->Oth,AppBoundedNotation(List.lengthargs+List.lengthargs')|NApp(NVar_,_)->Oth,AppUnboundedNotation|NApp(_,args)->Oth,AppBoundedNotation(List.lengthargs)|NList(_,_,NApp(NVarx,_),_,_)whenx=Notation_ops.ldots_var->Oth,AppUnboundedNotation|_->Oth,NotAppNotationletuninterp_notationsc=List.map_append(funkey->keymap_findkey!notations_key_table)(glob_constr_keysc)letuninterp_cases_pattern_notationsc=keymap_find(cases_pattern_keyc)!notations_key_tableletuninterp_ind_pattern_notationsind=keymap_find(RefKey(canonical_gr(GlobRef.IndRefind)))!notations_key_tableletremove_uninterpretationrule(metas,caspat)=let(key,n)=notation_constr_keycinnotations_key_table:=keymap_removekey{not_rule=rule;not_patt=pat;not_status=n}!notations_key_tableletdeclare_uninterpretationrule(metas,caspat)=let(key,n)=notation_constr_keycinnotations_key_table:=keymap_addkey{not_rule=rule;not_patt=pat;not_status=n}!notations_key_tableletfreeze()=!notations_key_tableletunfreezefkm=notations_key_table:=fkmletwith_notation_uninterpretation_protectionfx=letfs=freeze()intryleta=fxinunfreezefs;awithreraise->letreraise=Exninfo.capturereraiseinlet()=unfreezefsinExninfo.iraisereraise(** Miscellaneous *)typenotation_use=|OnlyPrinting|OnlyParsing|ParsingAndPrinting