123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123(************************************************************************)(* * 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) *)(************************************************************************)openPpopenCErrorsopenNamesopenLibnamesopenLibobjectopenLibopenNotation_termopenNotationextern(* Abbreviations. *)typeabbreviation={abbrev_pattern:interpretation;abbrev_onlyparsing:bool;abbrev_user_warns:UserWarn.toption;abbrev_activated:bool;(* Not really necessary in practice *)}letabbrev_table=Summary.ref(KNmap.empty:(full_path*abbreviation)KNmap.t)~name:"ABBREVIATIONS"letadd_abbreviationknspabbrev=abbrev_table:=KNmap.addkn(sp,abbrev)!abbrev_tablelettoggle_abbreviation~on~usekn=letsp,data=KNmap.findkn!abbrev_tableinifdata.abbrev_activated!=onthenbeginabbrev_table:=KNmap.addkn(sp,{datawithabbrev_activated=on})!abbrev_table;matchusewith|OnlyPrinting->()|OnlyParsing|ParsingAndPrinting->ifonthenbeginNametab.push_abbreviation?user_warns:data.abbrev_user_warns(Nametab.Until1)spkn;Nametab.push_abbreviation(Nametab.Exactly1)spknendelseNametab.remove_abbreviationspknendlettoggle_abbreviations~on~usefilter=KNmap.fold(funkn(sp,abbrev)()->ifabbrev.abbrev_activated!=on&&filterspabbrev.abbrev_patternthentoggle_abbreviation~on~usekn)!abbrev_table()letload_abbreviationi((sp,kn),(_local,abbrev))=ifNametab.exists_ccispthenuser_err(Id.print(basenamesp)++str" already exists.");add_abbreviationknspabbrev;Nametab.push_abbreviation?user_warns:abbrev.abbrev_user_warns(Nametab.Untili)spknletis_alias_of_already_visible_namesp=function|_,NRef(ref,None)->let(dir,id)=repr_qualid(Nametab.shortest_qualid_of_globalId.Set.emptyref)inDirPath.is_emptydir&&Id.equalid(basenamesp)|_->falseletopen_abbreviationi((sp,kn),(_local,abbrev))=letpat=abbrev.abbrev_patterninifnot(Int.equali1&&is_alias_of_already_visible_namesppat)thenbeginNametab.push_abbreviation(Nametab.Exactlyi)spkn;ifnotabbrev.abbrev_onlyparsingthen(* Redeclare it to be used as (short) name in case an other (distfix)
notation was declared in between *)Notationextern.declare_uninterpretation(AbbrevRulekn)patendletimport_abbreviationispkn=let_,abbrev=KNmap.getkn!abbrev_tableinopen_abbreviationi((sp,kn),(false,abbrev))letcache_abbreviationd=load_abbreviation1d;open_abbreviation1dletsubst_abbreviation(subst,(local,abbrev))=letabbrev_pattern=Notation_ops.subst_interpretationsubstabbrev.abbrev_patternin(local,{abbrevwithabbrev_pattern})letclassify_abbreviation(local,_)=iflocalthenDisposeelseSubstituteletinAbbreviation:Id.t->(bool*abbreviation)->obj=declare_named_object{(default_object"ABBREVIATION")withcache_function=cache_abbreviation;load_function=load_abbreviation;open_function=simple_openopen_abbreviation;subst_function=subst_abbreviation;classify_function=classify_abbreviation}letdeclare_abbreviation~localuser_warnsid~onlyparsingpat=letabbrev={abbrev_pattern=pat;abbrev_onlyparsing=onlyparsing;abbrev_user_warns=user_warns;abbrev_activated=true;}inadd_leaf(inAbbreviationid(local,abbrev))(* Remark: do not check for activation (if not activated, it is already not supposed to be located) *)letsearch_abbreviationkn=let_,abbrev=KNmap.findkn!abbrev_tableinabbrev.abbrev_patternletsearch_filtered_abbreviationfilterkn=let_,abbrev=KNmap.findkn!abbrev_tableinletres=filterabbrev.abbrev_patterninres