Copyright | Koen Claessen 2003 |
---|---|
License | GPL |
Maintainer | JP Bernardy |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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
- data Parser s a
- type Expect s = [(String, Maybe s)]
- module Text.ParserCombinators.Class
- type ParseMethod s a r = P s a -> [s] -> ParseResult s r
- type ParseResult s r = Either (Err s) r
- mapErrR :: (s -> s') -> ParseResult s r -> ParseResult s' r
- parseFromFile :: Parser Char a -> ParseMethod Char a r -> FilePath -> IO (ParseResult Char r)
- parse :: Parser s a -> ParseMethod s a r -> [s] -> ParseResult s r
- shortestResult :: ParseMethod s a a
- longestResult :: ParseMethod s a a
- longestResults :: ParseMethod s a [a]
- allResults :: ParseMethod s a [a]
- allResultsStaged :: ParseMethod s a [[a]]
- completeResults :: ParseMethod s a [a]
- shortestResultWithLeftover :: ParseMethod s a (a, [s])
- longestResultWithLeftover :: ParseMethod s a (a, [s])
- longestResultsWithLeftover :: ParseMethod s a ([a], Maybe [s])
- allResultsWithLeftover :: ParseMethod s a [(a, [s])]
- module Control.Applicative
- guard :: Alternative f => Bool -> f ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- ap :: Monad m => m (a -> b) -> m a -> m b
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
Documentation
Instances
Monad (Parser s) Source # | |
Functor (Parser s) Source # | |
MonadFail (Parser s) Source # | |
Defined in Text.ParserCombinators.Parsek | |
Applicative (Parser s) Source # | |
Alternative (Parser s) Source # | |
MonadPlus (Parser s) Source # | |
IsParser (Parser s) Source # | |
Defined in Text.ParserCombinators.Parsek | |
type SymbolOf (Parser s) Source # | |
Defined in Text.ParserCombinators.Parsek |
module Text.ParserCombinators.Class
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 #
parseFromFile :: Parser Char a -> ParseMethod Char a r -> FilePath -> IO (ParseResult Char r) Source #
parse :: Parser s a -> ParseMethod s a r -> [s] -> ParseResult s r Source #
shortestResult :: ParseMethod s a a Source #
longestResult :: ParseMethod s a a Source #
longestResults :: ParseMethod s a [a] Source #
allResults :: ParseMethod s a [a] Source #
allResultsStaged :: ParseMethod s a [[a]] Source #
completeResults :: ParseMethod s a [a] Source #
shortestResultWithLeftover :: ParseMethod s a (a, [s]) Source #
longestResultWithLeftover :: ParseMethod s a (a, [s]) Source #
longestResultsWithLeftover :: ParseMethod s a ([a], Maybe [s]) Source #
allResultsWithLeftover :: ParseMethod s a [(a, [s])] Source #
module Control.Applicative
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative
computations. Defined by
guard True =pure
() guard False =empty
Examples
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
otherwise. For example:Just
(x `div`
y)
>>> 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)
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Monads that also support choice and failure.
Nothing
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>
)
Instances
MonadPlus [] | Since: base-2.1 |
MonadPlus Maybe | Since: base-2.1 |
MonadPlus IO | Since: base-4.9.0.0 |
MonadPlus ReadP | Since: base-2.1 |
MonadPlus P | Since: base-2.1 |
Defined in Text.ParserCombinators.ReadP | |
MonadPlus Parser Source # | |
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | Since: base-4.6.0.0 |
Defined in Control.Arrow mzero :: ArrowMonad a a0 # mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 # | |
MonadPlus (Parser s) Source # | |