123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(************************************************************************)(* * 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) *)(************************************************************************)openPpopenCErrorsopenNamesopenLibnamesopenLibobjectopenLibopenNotationexterntypeabbreviation={abbrev_local:Libobject.locality;abbrev_pattern:Notation_term.interpretation;abbrev_onlyparsing:bool;abbrev_user_warns:Globnames.extended_global_referenceUserWarn.with_qfoption;abbrev_activated:bool;(* Not really necessary in practice *)abbrev_src:Loc.toption;}typedata=full_path*abbreviationletinterp(_,a)=a.abbrev_patternletfull_path(fp,_)=fpletenabled(_,a)=a.abbrev_activatedletonly_parsing(_,a)=a.abbrev_onlyparsingletabbrev_table=Summary.ref(KerName.Map.empty:dataKerName.Map.t)~name:"ABBREVIATIONS"letaddknfpa=abbrev_table:=KerName.Map.addknfpa!abbrev_tableletfoldfacc=KerName.Map.foldf!abbrev_tableaccletfind_optk=KerName.Map.find_optk!abbrev_tablelettoggle_aux~on~usek(sp,data)=ifdata.abbrev_activated!=onthenbeginabbrev_table:=KerName.Map.addk(sp,{datawithabbrev_activated=on})!abbrev_table;matchusewith|OnlyPrinting->()|(OnlyParsing|ParsingAndPrinting)whenon->Nametab.push_abbreviation?user_warns:data.abbrev_user_warns(Nametab.Until1)spk;Nametab.push_abbreviation(Nametab.Exactly1)spk|OnlyParsing|ParsingAndPrinting->Nametab.remove_abbreviationspkendlettoggle~on~usek=toggle_aux~on~usek(KerName.Map.findk!abbrev_table)lettoggle_if~on~usefilter=fold(funk((_,a)asabbr)_->ifa.abbrev_activated!=on&&filterkabbrthentoggle_aux~on~usekabbr)()letis_alias_of_already_visible_namesp=function|_,Notation_term.NRef(ref,None)->let(dir,id)=repr_qualid(Nametab.shortest_qualid_of_global~force_short:trueId.Set.emptyref)inDirPath.is_emptydir&&Id.equalid(basenamesp)|_->falseletload_abbreviationi((sp,kn),abbrev)=ifNametab.exists_ccispthenuser_err(Id.print(basenamesp)++str" already exists.");addkn(sp,abbrev);Nametab.push_abbreviation?user_warns:abbrev.abbrev_user_warns(Nametab.Untili)spkn;abbrev.abbrev_src|>Option.iter(funloc->Nametab.set_cci_src_loc(Abbrevkn)loc);letpat=abbrev.abbrev_patterninlet()=ifnotabbrev.abbrev_onlyparsing&&abbrev.abbrev_local<>Export&¬(Int.equali1&&is_alias_of_already_visible_namesppat)thenNotationextern.declare_uninterpretation(Global.env())(AbbrevRulekn)patin()letopen_abbreviationi((sp,kn),abbrev)=letpat=abbrev.abbrev_patterninifnot(Int.equali1&&is_alias_of_already_visible_namesppat)thenbeginNametab.push_abbreviation(Nametab.Exactlyi)spkn;ifnotabbrev.abbrev_onlyparsing&&Int.equali1&&abbrev.abbrev_local<>SuperGlobalthenNotationextern.declare_uninterpretation(Global.env())(AbbrevRulekn)patendletimportispkn=let_,abbrev=KerName.Map.getkn!abbrev_tableinopen_abbreviationi((sp,kn),abbrev)letcache_abbreviationd=load_abbreviation1d;open_abbreviation1dletsubst_abbreviation(subst,abbrev)=letabbrev_pattern=Notation_ops.subst_interpretationsubstabbrev.abbrev_patternin{abbrevwithabbrev_pattern}letclassify_abbreviationabbrev=ifabbrev.abbrev_local=LocalthenDisposeelseSubstituteletinAbbreviation:Id.t->abbreviation->obj=declare_named_object{(default_object"ABBREVIATION")withcache_function=cache_abbreviation;load_function=load_abbreviation;open_function=filtered_openopen_abbreviation;subst_function=subst_abbreviation;classify_function=classify_abbreviation}letdeclare~localuser_warnsid~onlyparsingpat=letabbrev={abbrev_local=local;abbrev_pattern=pat;abbrev_onlyparsing=onlyparsing;abbrev_user_warns=user_warns;abbrev_activated=true;abbrev_src=Loc.get_current_command_loc();}inadd_leaf(inAbbreviationidabbrev)(* Remark: do not check for activation (if not activated, it is already not supposed to be located) *)letfind_interpkn=let_,abbrev=KerName.Map.findkn!abbrev_tableinabbrev.abbrev_pattern