parsek-1.0.3.0: Parallel Parsing Processes

CopyrightKoen Claessen 2003
LicenseGPL
MaintainerJP Bernardy
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Text.ParserCombinators.Parsek

Description

This module provides the Parsek library developed by Koen Claessen in his functional pearl article Parallel Parsing Processes, Journal of Functional Programming, 14(6), 741-757, Cambridge University Press, 2004:

http://www.cs.chalmers.se/~koen/pubs/entry-jfp04-parser.html

Synopsis

Documentation

data Parser s a Source #

Instances
Monad (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

(>>=) :: Parser s a -> (a -> Parser s b) -> Parser s b #

(>>) :: Parser s a -> Parser s b -> Parser s b #

return :: a -> Parser s a #

fail :: String -> Parser s a #

Functor (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

fmap :: (a -> b) -> Parser s a -> Parser s b #

(<$) :: a -> Parser s b -> Parser s a #

MonadFail (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

fail :: String -> Parser s a #

Applicative (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

pure :: a -> Parser s a #

(<*>) :: Parser s (a -> b) -> Parser s a -> Parser s b #

liftA2 :: (a -> b -> c) -> Parser s a -> Parser s b -> Parser s c #

(*>) :: Parser s a -> Parser s b -> Parser s b #

(<*) :: Parser s a -> Parser s b -> Parser s a #

Alternative (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

empty :: Parser s a #

(<|>) :: Parser s a -> Parser s a -> Parser s a #

some :: Parser s a -> Parser s [a] #

many :: Parser s a -> Parser s [a] #

MonadPlus (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

mzero :: Parser s a #

mplus :: Parser s a -> Parser s a -> Parser s a #

IsParser (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Associated Types

type SymbolOf (Parser s) :: Type Source #

Methods

satisfy :: (SymbolOf (Parser s) -> Bool) -> Parser s (SymbolOf (Parser s)) Source #

look :: Parser s [SymbolOf (Parser s)] Source #

label :: String -> Parser s a -> Parser s a Source #

(<<|>) :: Parser s a -> Parser s a -> Parser s a Source #

type SymbolOf (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

type SymbolOf (Parser s) = s

type Expect s = [(String, Maybe s)] Source #

An intersection (nesting) of things currently expected

type ParseMethod s a r = P s a -> [s] -> ParseResult s r Source #

type ParseResult s r = Either (Err s) r Source #

mapErrR :: (s -> s') -> ParseResult s r -> ParseResult s' r Source #

parse :: Parser s a -> ParseMethod s a r -> [s] -> ParseResult s r Source #

guard :: Alternative f => Bool -> f () #

Conditional failure of Alternative computations. Defined by

guard True  = pure ()
guard False = empty

Examples

Expand

Common uses of guard include conditionally signaling an error in an error monad and conditionally rejecting the current choice in an Alternative-based parser.

As an example of signaling an error in the error monad Maybe, consider a safe division function safeDiv x y that returns Nothing when the denominator y is zero and Just (x `div` y) otherwise. For example:

>>> safeDiv 4 0
Nothing
>>> safeDiv 4 2
Just 2

A definition of safeDiv using guards, but not guard:

safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0    = Just (x `div` y)
            | otherwise = Nothing

A definition of safeDiv using guard and Monad do-notation:

safeDiv :: Int -> Int -> Maybe Int
safeDiv x y = do
  guard (y /= 0)
  return (x `div` y)

forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m () #

forM_ is mapM_ with its arguments flipped. For a version that doesn't ignore the results see forM.

As of base 4.8.0.0, forM_ is just for_, specialized to Monad.

ap :: Monad m => m (a -> b) -> m a -> m b #

In many situations, the liftM operations can be replaced by uses of ap, which promotes function application.

return f `ap` x1 `ap` ... `ap` xn

is equivalent to

liftMn f x1 x2 ... xn

class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #

Monads that also support choice and failure.

Minimal complete definition

Nothing

Methods

mzero :: m a #

The identity of mplus. It should also satisfy the equations

mzero >>= f  =  mzero
v >> mzero   =  mzero

The default definition is

mzero = empty

mplus :: m a -> m a -> m a #

An associative operation. The default definition is

mplus = (<|>)
Instances
MonadPlus []

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

mzero :: [a] #

mplus :: [a] -> [a] -> [a] #

MonadPlus Maybe

Since: base-2.1

Instance details

Defined in GHC.Base

Methods

mzero :: Maybe a #

mplus :: Maybe a -> Maybe a -> Maybe a #

MonadPlus IO

Since: base-4.9.0.0

Instance details

Defined in GHC.Base

Methods

mzero :: IO a #

mplus :: IO a -> IO a -> IO a #

MonadPlus ReadP

Since: base-2.1

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

mzero :: ReadP a #

mplus :: ReadP a -> ReadP a -> ReadP a #

MonadPlus P

Since: base-2.1

Instance details

Defined in Text.ParserCombinators.ReadP

Methods

mzero :: P a #

mplus :: P a -> P a -> P a #

MonadPlus Parser Source # 
Instance details

Defined in Text.ParserCombinators.Parsek.Position

Methods

mzero :: Parser a #

mplus :: Parser a -> Parser a -> Parser a #

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

mzero :: ArrowMonad a a0 #

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

MonadPlus (Parser s) Source # 
Instance details

Defined in Text.ParserCombinators.Parsek

Methods

mzero :: Parser s a #

mplus :: Parser s a -> Parser s a -> Parser s a #