{-# LANGUAGE RankNTypes,
GADTs,
MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances,
FlexibleContexts,
UndecidableInstances,
NoMonomorphismRestriction,
ImpredicativeTypes #-}moduleText.ParserCombinators.UU.DerivedwhereimportText.ParserCombinators.UU.CorepReturn=purepFail=emptyinfixl4<??>infixl2`opt`-- | Optionally recognize parser 'p'.-- -- If 'p' can be recognized, the return value of 'p' is used. Otherwise,-- the value 'v' is used. Note that opt is greedy, if you do not want-- this use @... <|> pure v@ instead. Furthermore, 'p' should not-- recognise the empty string, since this would make your parser ambiguous!!opt::Psta->a->Pstap`opt`v=p<<|>purevpMaybe::Psta->Pst(Maybea)pMaybep=Just<$>p`opt`NothingpEitherpq=Left<$>p<|>Right<$>q(<$$>)::(a->b->c)->Pstb->Pst(a->c)f<$$>p=flipf<$>p(<??>)::Psta->Pst(a->a)->Pstap<??>q=p<**>(q`opt`id)-- | This can be used to parse 'x' surrounded by 'l' and 'r'.-- -- Example:---- > pParens = pPacked pOParen pCParenpPacked::Pstb1->Pstb2->Psta->PstapPackedlrx=l*>x<*r-- =======================================================================================-- ===== Iterating ps ===============================================================-- =======================================================================================pFoldr::(a->a1->a1,a1)->Psta->Psta1pFoldr_ng::(a->a1->a1,a1)->Psta->Psta1pFoldralg@(op,e)p=pfmwherepfm=(op<$>p<*>pfm)`opt`epFoldr_ngalg@(op,e)p=pfmwherepfm=(op<$>p<*>pfm)<|>pureepFoldr1::(v->b->b,b)->Pstv->PstbpFoldr1_ng::(v->b->b,b)->Pstv->PstbpFoldr1alg@(op,e)p=op<$>p<*>pFoldralgppFoldr1_ngalg@(op,e)p=op<$>p<*>pFoldr_ngalgppFoldrSep::(v->b->b,b)->Psta->Pstv->PstbpFoldrSep_ng::(v->b->b,b)->Psta->Pstv->PstbpFoldrSepalg@(op,e)sepp=op<$>p<*>pFoldralgsepp`opt`ewheresepp=sep*>ppFoldrSep_ngalg@(op,e)sepp=op<$>p<*>pFoldr_ngalgsepp<|>pureewheresepp=sep*>ppFoldr1Sep::(a->b->b,b)->Psta1->Psta->PstbpFoldr1Sep_ng::(a->b->b,b)->Psta1->Psta->PstbpFoldr1Sepalg@(op,e)sepp=pfmwherepfm=op<$>p<*>pFoldralg(sep*>p)pFoldr1Sep_ngalg@(op,e)sepp=pfmwherepfm=op<$>p<*>pFoldr_ngalg(sep*>p)list_alg::(a->[a]->[a],[a1])list_alg=((:),[])pList::Psta->Pst[a]pList_ng::Psta->Pst[a]pListp=pFoldrlist_algppList_ngp=pFoldr_nglist_algppList1::Psta->Pst[a]pList1_ng::Psta->Pst[a]pList1p=pFoldr1list_algppList1_ngp=pFoldr1_nglist_algppListSep::Psta1->Psta->Pst[a]pListSep_ng::Psta1->Psta->Pst[a]pListSepsepp=pFoldrSeplist_algsepppListSep_ngsepp=pFoldrSep_nglist_algsepppList1Sep::Psta1->Psta->Pst[a]pList1Sep_ng::Psta1->Psta->Pst[a]pList1Sepsp=pFoldr1Seplist_algsppList1Sep_ngsp=pFoldr1Sep_nglist_algsppChainr::Pst(c->c->c)->Pstc->PstcpChainr_ng::Pst(c->c->c)->Pstc->PstcpChainropx=rwherer=x<??>(flip<$>op<*>r)pChainr_ngopx=rwherer=x<**>((flip<$>op<*>r)<|>pureid)pChainl::Pst(c->c->c)->Pstc->PstcpChainl_ng::Pst(c->c->c)->Pstc->PstcpChainlopx=f<$>x<*>pList(flip<$>op<*>x)wherefx[]=xfx(func:rest)=f(funcx)restpChainl_ngopx=f<$>x<*>pList_ng(flip<$>op<*>x)wherefx[]=xfx(func:rest)=f(funcx)rest-- | Parses using any of the parsers in the list 'l'.pAny::(a->Psta1)->[a]->Psta1pAnyfl=foldr(<|>)pFail(mapfl)-- | Parses any of the symbols in 'l'.pAnySym::Providesstss=>[s]->PstspAnySym=pAnypSympToken::Providesstss=>[s]->Pst[s]pToken[]=pure[]pToken(a:as)=(:)<$>pSyma<*>pTokenaspAnyToken::Providesstss=>[[s]]->Pst[s]pAnyToken=pAnypToken