123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134(************************************************************************)(* * 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_deprecation:Deprecation.toption;abbrev_also_in_cases_pattern:bool;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(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(Nametab.Untili)spknletis_alias_of_already_visible_namesp=function|_,NRef(ref,_)->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~also_in_cases_pattern:abbrev.abbrev_also_in_cases_pattern(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~local?(also_in_cases_pattern=true)deprecationid~onlyparsingpat=letabbrev={abbrev_pattern=pat;abbrev_onlyparsing=onlyparsing;abbrev_deprecation=deprecation;abbrev_also_in_cases_pattern=also_in_cases_pattern;abbrev_activated=true;}inadd_leaf(inAbbreviationid(local,abbrev))letpr_abbreviationkn=pr_qualid(Nametab.shortest_qualid_of_abbreviationId.Set.emptykn)letwarn_deprecated_abbreviation=Deprecation.create_warning~object_name:"Notation"~warning_name:"deprecated-syntactic-definition"pr_abbreviation(* Remark: do not check for activation (if not activated, it is already not supposed to be located) *)letsearch_abbreviation?lockn=let_,abbrev=KNmap.findkn!abbrev_tableinOption.iter(fund->warn_deprecated_abbreviation?loc(kn,d))abbrev.abbrev_deprecation;abbrev.abbrev_patternletsearch_filtered_abbreviation?locfilterkn=let_,abbrev=KNmap.findkn!abbrev_tableinletres=filterabbrev.abbrev_patterninifOption.has_someresthenOption.iter(fund->warn_deprecated_abbreviation?loc(kn,d))abbrev.abbrev_deprecation;res