Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude #-}------------------------------------------------------------------------------- |-- Module : Text.ParserCombinators.ReadPrec-- Copyright : (c) The University of Glasgow 2002-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org-- Stability : provisional-- Portability : non-portable (uses Text.ParserCombinators.ReadP)---- This library defines parser combinators for precedence parsing.-----------------------------------------------------------------------------moduleText.ParserCombinators.ReadPrec(ReadPrec,-- * PrecedencesPrec,minPrec,-- * Precedence operationslift,prec,step,reset,-- * Other operations-- | All are based directly on their similarly-named 'ReadP' counterparts.get,look,(+++),(<++),pfail,choice,-- * ConvertersreadPrec_to_P,readP_to_Prec,readPrec_to_S,readS_to_Prec,)whereimportText.ParserCombinators.ReadP(ReadP,ReadS,readP_to_S,readS_to_P)importqualifiedText.ParserCombinators.ReadPasReadP(get,look,(+++),(<++),pfail)importGHC.Num(Num(..))importGHC.BaseimportqualifiedControl.Monad.FailasMonadFail-- ----------------------------------------------------------------------------- The readPrec typenewtypeReadPreca=P(Prec->ReadPa)-- Functor, Monad, MonadPlus-- | @since 2.01instanceFunctorReadPrecwherefmaph(Pf)=P(\n->fmaph(fn))-- | @since 4.6.0.0instanceApplicativeReadPrecwherepurex=P(\_->purex)(<*>)=apliftA2=liftM2-- | @since 2.01instanceMonadReadPrecwherefails=P(\_->fails)Pf>>=k=P(\n->doa<-fn;letPf'=kainf'n)-- | @since 4.9.0.0instanceMonadFail.MonadFailReadPrecwherefails=P(\_->MonadFail.fails)-- | @since 2.01instanceMonadPlusReadPrec-- | @since 4.6.0.0instanceAlternativeReadPrecwhereempty=pfail(<|>)=(+++)-- precedencestypePrec=IntminPrec::PrecminPrec=0-- ----------------------------------------------------------------------------- Operations over ReadPreclift::ReadPa->ReadPreca-- ^ Lift a precedence-insensitive 'ReadP' to a 'ReadPrec'.liftm=P(\_->m)step::ReadPreca->ReadPreca-- ^ Increases the precedence context by one.step(Pf)=P(\n->f(n+1))reset::ReadPreca->ReadPreca-- ^ Resets the precedence context to zero.reset(Pf)=P(\_->fminPrec)prec::Prec->ReadPreca->ReadPreca-- ^ @(prec n p)@ checks whether the precedence context is-- less than or equal to @n@, and---- * if not, fails---- * if so, parses @p@ in context @n@.precn(Pf)=P(\c->ifc<=nthenfnelseReadP.pfail)-- ----------------------------------------------------------------------------- Derived operationsget::ReadPrecChar-- ^ Consumes and returns the next character.-- Fails if there is no input left.get=liftReadP.getlook::ReadPrecString-- ^ Look-ahead: returns the part of the input that is left, without-- consuming it.look=liftReadP.look(+++)::ReadPreca->ReadPreca->ReadPreca-- ^ Symmetric choice.Pf1+++Pf2=P(\n->f1nReadP.+++f2n)(<++)::ReadPreca->ReadPreca->ReadPreca-- ^ Local, exclusive, left-biased choice: If left parser-- locally produces any result at all, then right parser is-- not used.Pf1<++Pf2=P(\n->f1nReadP.<++f2n)pfail::ReadPreca-- ^ Always fails.pfail=liftReadP.pfailchoice::[ReadPreca]->ReadPreca-- ^ Combines all parsers in the specified list.choiceps=foldr(+++)pfailps-- ----------------------------------------------------------------------------- Converting between ReadPrec and ReadreadPrec_to_P::ReadPreca->(Int->ReadPa)readPrec_to_P(Pf)=freadP_to_Prec::(Int->ReadPa)->ReadPrecareadP_to_Precf=PfreadPrec_to_S::ReadPreca->(Int->ReadSa)readPrec_to_S(Pf)n=readP_to_S(fn)readS_to_Prec::(Int->ReadSa)->ReadPrecareadS_to_Precf=P(\n->readS_to_P(fn))
[8]ページ先頭