123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(************************************************************************)(* * 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_term(* Abbreviations. *)typeabbreviation={abbrev_pattern:interpretation;abbrev_onlyparsing:bool;abbrev_deprecation:Deprecation.toption;abbrev_also_in_cases_pattern:bool;}letabbrev_table=Summary.ref(KNmap.empty:abbreviationKNmap.t)~name:"ABBREVIATIONS"letadd_abbreviationknabbrev=abbrev_table:=KNmap.addknabbrev!abbrev_tableletload_abbreviationi((sp,kn),(_local,abbrev))=ifNametab.exists_ccispthenuser_err(Id.print(basenamesp)++str" already exists.");add_abbreviationknabbrev;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 *)Notation.declare_uninterpretation~also_in_cases_pattern:abbrev.abbrev_also_in_cases_pattern(AbbrevRulekn)patendletimport_abbreviationispkn=letabbrev=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;}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_abbreviationletsearch_abbreviation?lockn=letabbrev=KNmap.findkn!abbrev_tableinOption.iter(fund->warn_deprecated_abbreviation?loc(kn,d))abbrev.abbrev_deprecation;abbrev.abbrev_patternletsearch_filtered_abbreviation?locfilterkn=letabbrev=KNmap.findkn!abbrev_tableinletres=filterabbrev.abbrev_patterninifOption.has_someresthenOption.iter(fund->warn_deprecated_abbreviation?loc(kn,d))abbrev.abbrev_deprecation;res