{-# LANGUAGE CPP #-}moduleAgda.TypeChecking.QuotewhereimportControl.ApplicativeimportAgda.Syntax.PositionimportAgda.Syntax.LiteralimportAgda.Syntax.InternalimportAgda.Syntax.CommonimportAgda.TypeChecking.MonadimportAgda.TypeChecking.Monad.BuiltinimportAgda.TypeChecking.ReduceimportAgda.TypeChecking.PrettyimportAgda.TypeChecking.Substitute#include "../undefined.h"importAgda.Utils.ImpossiblequotingKit::TCM((Term->Term),(Type->Term))quotingKit=dohidden<-primHiddeninstanceH<-primInstancevisible<-primVisiblerelevant<-primRelevantirrelevant<-primIrrelevantnil<-primNilcons<-primConsarg<-primArgArgvar<-primAgdaTermVarlam<-primAgdaTermLamdef<-primAgdaTermDefcon<-primAgdaTermConpi<-primAgdaTermPisort<-primAgdaTermSortset<-primAgdaSortSetsetLit<-primAgdaSortLitunsupportedSort<-primAgdaSortUnsupportedsucLevel<-primLevelSuclub<-primLevelMaxel<-primAgdaTypeElConz_<-primZeroCons_<-primSucunsupported<-primAgdaTermUnsupportedlett@@u=applyt[defaultArgu]quoteHidingHidden=hiddenquoteHidingInstance=instanceHquoteHidingNotHidden=visiblequoteRelevanceRelevant=relevantquoteRelevanceIrrelevant=irrelevantquoteRelevanceNonStrict=relevantquoteRelevanceForced=relevantquoteLit(LitInt_n)=iteratesuczero!!fromIntegralnquoteLit_=unsupported-- We keep no ranges in the quoted term, so the equality on terms-- is only on the structure.quoteSortLevelTerm(Max[])=setLit@@Lit(LitIntnoRange0)quoteSortLevelTerm(Max[ClosedLeveln])=setLit@@Lit(LitIntnoRangen)quoteSortLevelTerm(Max[Plus0(NeutralLevelv)])=set@@quotevquoteSortLevelTerm_=unsupportedquoteSort(Typet)=quoteSortLevelTermtquoteSortProp=unsupportedSortquoteSortInf=unsupportedSortquoteSortDLub{}=unsupportedSortquoteType(Elst)=el@@quoteSorts@@quotetlist[]=nillist(a:as)=cons@@a@@listaszero=con@@quoteNamez@@nilsucn=con@@quoteNames@@list[arg@@visible@@relevant@@n]quoteArgq(Arghrt)=arg@@quoteHidingh@@quoteRelevancer@@qtquoteArgsts=list(map(quoteArgquote)ts)quote(Varnts)=var@@Lit(LitIntnoRangen)@@quoteArgstsquote(Lamht)=lam@@quoteHidingh@@quote(absBodyt)quote(Defxts)=def@@quoteNamex@@quoteArgstsquote(Conxts)=con@@quoteNamex@@quoteArgstsquote(Pitu)=pi@@quoteArgquoteTypet@@quoteType(absBodyu)quote(Level_)=unsupportedquote(Litlit)=quoteLitlitquote(Sorts)=sort@@quoteSortsquoteMetaV{}=unsupportedquoteDontCare{}=unsupported-- could be exposed at some point but we have to take carereturn(quote,quoteType)quoteName::QName->TermquoteNamex=Lit(LitQNamenoRangex)quoteTerm::Term->TCMTermquoteTermv=($v).fst<$>quotingKitquoteType::Type->TCMTermquoteTypev=($v).snd<$>quotingKitagdaTermType::TCMTypeagdaTermType=El(mkType0)<$>primAgdaTermqNameType::TCMTypeqNameType=El(mkType0)<$>primQNameisCon::QName->TCMTerm->TCMBoolisConcontm=dot<-tmcasetofConcon'_->return(con==con')_->returnFalseunquoteFailedGeneric::String->TCMaunquoteFailedGenericmsg=typeError.GenericError$"Unable to unquote the "++msgunquoteFailed::String->String->Term->TCMaunquoteFailedkindmsgt=dodoc<-prettyTCMtunquoteFailedGeneric$"term ("++showdoc++") of type "++kind++".\nReason: "++msg++"."classUnquoteawhereunquote::Term->TCMaunquoteH::Unquotea=>ArgTerm->TCMaunquoteH(ArgHiddenRelevantx)=unquotexunquoteH_=unquoteFailedGeneric"argument. It should be `hidden'."unquoteN::Unquotea=>ArgTerm->TCMaunquoteN(ArgNotHiddenRelevantx)=unquotexunquoteN_=unquoteFailedGeneric"argument. It should be `visible'"choice::Monadm=>[(mBool,ma)]->ma->machoice[]dflt=dfltchoice((mb,mx):mxs)dflt=dob<-mbifbthenmxelsechoicemxsdfltinstanceUnquotea=>Unquote(Arga)whereunquotet=dot<-reducetcasetofConc[hid,rel,x]->dochoice[(c`isCon`primArgArg,Arg<$>unquoteNhid<*>unquoteNrel<*>unquoteNx)](unquoteFailed"Arg""arity 3 and not the `arg' constructor"t)_->unquoteFailed"Arg""not of arity 3"tinstanceUnquoteIntegerwhereunquotet=dot<-reducetcasetofLit(LitInt_n)->returnn_->unquoteFailed"Integer""not a literal integer"tinstanceUnquotea=>Unquote[a]whereunquotet=dot<-reducetcasetofConc[x,xs]->dochoice[(c`isCon`primCons,(:)<$>unquoteNx<*>unquoteNxs)](unquoteFailed"List""arity 2 and not the `∷' constructor"t)Conc[]->dochoice[(c`isCon`primNil,return[])](unquoteFailed"List""arity 0 and not the `[]' constructor"t)_->unquoteFailed"List""neither `[]' nor `∷'"tinstanceUnquoteHidingwhereunquotet=dot<-reducetcasetofConc[]->dochoice[(c`isCon`primHidden,returnHidden),(c`isCon`primInstance,returnInstance),(c`isCon`primVisible,returnNotHidden)](unquoteFailed"Hiding""neither `hidden' nor `visible'"t)_->unquoteFailed"Hiding""arity is not 0"tinstanceUnquoteRelevancewhereunquotet=dot<-reducetcasetofConc[]->dochoice[(c`isCon`primRelevant,returnRelevant),(c`isCon`primIrrelevant,returnIrrelevant)](unquoteFailed"Relevance""neither `relevant' or `irrelevant'"t)_->unquoteFailed"Relevance""arity is not 0"tinstanceUnquoteQNamewhereunquotet=dot<-reducetcasetofLit(LitQName_x)->returnx_->unquoteFailed"QName""not a literal qname value"tinstanceUnquotea=>Unquote(Absa)whereunquotet=dox<-freshNoName_Abs(showx)<$>unquotetinstanceUnquoteSortwhereunquotet=dot<-reducetcasetofConc[]->dochoice[(c`isCon`primAgdaSortUnsupported,unquoteFailed"Sort""unsupported sort"t)](unquoteFailed"Sort""arity 0 and not the `unsupported' constructor"t)Conc[u]->dochoice[(c`isCon`primAgdaSortSet,Type<$>unquoteNu),(c`isCon`primAgdaSortLit,Type.levelMax.(:[]).ClosedLevel<$>unquoteNu)](unquoteFailed"Sort""arity 1 and not the `set' or the `lit' constructors"t)_->unquoteFailed"Sort""not of arity 0 nor 1"tinstanceUnquoteLevelwhereunquotel=Max.(:[]).Plus0.UnreducedLevel<$>unquotelinstanceUnquoteTypewhereunquotet=dot<-reducetcasetofConc[s,u]->dochoice[(c`isCon`primAgdaTypeEl,El<$>unquoteNs<*>unquoteNu)](unquoteFailed"Type""arity 2 and not the `el' constructor"t)_->unquoteFailed"Type""not of arity 2"tinstanceUnquoteTermwhereunquotet=dot<-reducetcasetofConc[]->choice[(c`isCon`primAgdaTermUnsupported,unquoteFailed"Term""unsupported term"t)](unquoteFailed"Term""arity 0 and not the `unsupported' constructor"t)Conc[x]->dochoice[(c`isCon`primAgdaTermSort,Sort<$>unquoteNx)](unquoteFailed"Term""arity 1 and not the `sort' constructor"t)Conc[x,y]->choice[(c`isCon`primAgdaTermVar,Var<$>unquoteNx<*>unquoteNy),(c`isCon`primAgdaTermCon,Con<$>unquoteNx<*>unquoteNy),(c`isCon`primAgdaTermDef,Def<$>unquoteNx<*>unquoteNy),(c`isCon`primAgdaTermLam,Lam<$>unquoteNx<*>unquoteNy),(c`isCon`primAgdaTermPi,Pi<$>unquoteNx<*>unquoteNy)](unquoteFailed"Term""arity 2 and none of Var, Con, Def, Lam, Pi"t)Con{}->unquoteFailed"Term""neither arity 0 nor 1 nor 2"tLit{}->unquoteFailed"Term""unexpected literal"t_->unquoteFailed"Term""not a constructor"t