Safe Haskell | None |
---|---|
Language | Haskell2010 |
A module providing simple Parser combinator functionality. Useful for small parsing tasks such as identifier parsing or command-line argument parsing
- module Definitive
- data Proxy a = Proxy
- newtype ParserT s m a = ParserT (StateT s (LogicT m) a)
- type Parser c a = ParserT c Id a
- newtype ParserA m s a = ParserA (ParserT s m a)
- i'ParserA :: Iso (ParserA m s a) (ParserA m' s' a') (ParserT s m a) (ParserT s' m' a')
- class Stream c s | s -> c where
- emptyStream :: Stream c s => s -> Bool
- parserT :: (Monad n, Monad m) => Iso (ParserT s m a) (ParserT t n b) (s -> m [(s, a)]) (t -> n [(t, b)])
- parser :: Iso (Parser s a) (Parser t b) (s -> [(s, a)]) (t -> [(t, b)])
- ioParser :: Parser a b -> a -> IO b
- matchesT :: (Monad f, Monoid m) => (a -> m) -> ParserT s f a -> s -> f m
- matches :: Monoid m => (a -> m) -> Parser s a -> s -> m
- readsParser :: Parser s a -> s -> [(a, s)]
- lookingAt :: MonadParser s m p => p a -> p a
- notLookingAt :: MonadParser s m p => p a -> p ()
- class (MonadLogic m p, Monoid (p ()), Monad p, Monad m) => MonadParser s m p | p -> m s where
- class ParseStreamType s where
- type StreamToken s :: *
- type StreamChar s :: *
- class (ParseStreamType s, Stream (StreamToken s) s) => ParseStream s where
- (>*>) :: Monad m => ParserT a m b -> ParserT b m c -> ParserT a m c
- (<*<) :: Monad m => ParserT b m c -> ParserT a m b -> ParserT a m c
- token :: (ParseStream s, MonadParser s m p) => p (StreamChar s)
- following :: (ParseStream s, MonadParser s m p) => p (StreamToken s)
- satisfy :: forall s m p. (MonadParser s m p, ParseStream s) => (StreamChar s -> Bool) -> p (StreamChar s)
- oneOf :: forall s t m p. (Eq (StreamChar s), Foldable t, ParseStream s, MonadParser s m p) => t (StreamChar s) -> p (StreamChar s)
- oneOfSet :: forall s m p. (Ord (StreamChar s), ParseStream s, MonadParser s m p) => Set (StreamChar s) -> p (StreamChar s)
- noneOf :: (Eq (StreamChar s), Foldable t, ParseStream s, MonadParser s m p) => t (StreamChar s) -> p (StreamChar s)
- single :: forall s m p. (MonadParser s m p, Eq (StreamChar s), ParseStream s) => StreamChar s -> p ()
- several :: (Eq (StreamChar s), Foldable t, MonadParser s m p, ParseStream s) => t (StreamChar s) -> p ()
- like :: (Eq (StreamChar s), MonadParser s m p, ParseStream s) => [StreamChar s] -> p ()
- keyword :: (Eq (StreamChar s), MonadParser s m p, Foldable t, ParseStream s) => a -> t (StreamChar s) -> p a
- remaining :: MonadParser s m p => p s
- eoi :: (MonadParser s m p, ParseStream s) => p ()
- readable :: (Monad m, Read a) => ParserT String m a
- number :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char, Num n) => p n
- digit :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char
- letter :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char
- alNum :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char
- quotedString :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => Char -> p String
- space :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p ()
- nbspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p ()
- hspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p ()
- nbhspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p ()
- eol :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p ()
- many :: MonadParser s m p => p a -> p [a]
- many1 :: MonadParser s m p => p a -> p [a]
- sepBy :: MonadParser s m p => p a -> p b -> p [a]
- sepBy1 :: MonadParser s m p => p a -> p b -> p [a]
- skipMany :: MonadParser s m p => p a -> p ()
- skipMany1 :: MonadParser s m p => p a -> p ()
- many' :: MonadParser s m p => p a -> p [a]
- many1' :: MonadParser s m p => p a -> p [a]
- sepBy' :: MonadParser s m p => p a -> p b -> p [a]
- sepBy1' :: MonadParser s m p => p a -> p b -> p [a]
- skipMany' :: MonadParser s m p => p a -> p ()
- skipMany1' :: MonadParser s m p => p a -> p ()
- chainl :: MonadParser s m p => p a -> p (a -> b -> a) -> p b -> p a
- chainl' :: MonadParser s m p => p a -> p (a -> b -> a) -> p b -> p a
- chainr :: MonadParser s m p => p a -> p (b -> a -> a) -> p b -> p a
- chainr' :: MonadParser s m p => p a -> p (b -> a -> a) -> p b -> p a
- option :: MonadParser s m p => a -> p a -> p a
- option' :: MonadParser s m p => a -> p a -> p a
- optionMaybe :: MonadParser s m p => p a -> p (Maybe a)
- optionMaybe' :: MonadParser s m p => p a -> p (Maybe a)
Documentation
module Definitive
A proxy type to specify response types
The ParserT Type
newtype ParserT s m a Source #
MonadReader r m => MonadReader r (ParserT s m) Source # | |
MonadWriter w m => MonadWriter w (ParserT s m) Source # | |
Monad m => MonadError Void (ParserT s m) Source # | |
Monad m => MonadParser s (StateT s m) (ParserT s m) Source # | |
MonadTrans (ParserT s) Source # | |
ConcreteMonad (ParserT s) Source # | |
Functor (ParserT s m) Source # | |
SemiApplicative (ParserT s m) Source # | |
Applicative (ParserT s m) Source # | |
Monad (ParserT s m) Source # | |
MonadFix m => MonadFix (ParserT s m) Source # | |
Unit (ParserT s m) Source # | |
Monad m => MonadLogic (StateT s m) (ParserT s m) Source # | |
(Monad m, ParseStream s, (~) * (StreamChar s) Char) => IsString (ParserT s m a) Source # | |
Semigroup (ParserT s m a) Source # | |
Monoid (ParserT s m a) Source # | |
The Stream class
emptyStream :: Stream c s => s -> Bool Source #
Test if a Stream is empty
Converting to/from Parsers
parserT :: (Monad n, Monad m) => Iso (ParserT s m a) (ParserT t n b) (s -> m [(s, a)]) (t -> n [(t, b)]) Source #
readsParser :: Parser s a -> s -> [(a, s)] Source #
lookingAt :: MonadParser s m p => p a -> p a Source #
notLookingAt :: MonadParser s m p => p a -> p () Source #
The MonadParser class
class (MonadLogic m p, Monoid (p ()), Monad p, Monad m) => MonadParser s m p | p -> m s where Source #
runStreamState :: State s a -> p a Source #
tokenParser :: ParseStream s => (StreamToken s -> Either [StreamChar s] Bool) -> p (StreamChar s) Source #
(<+?), (<+>) :: p a -> p a -> p a infixr 0 <+?, <+> Source #
Monad m => MonadParser s (StateT s m) (ParserT s m) Source # | |
(MonadParser s m p, Monoid (p ((), Void, Void))) => MonadParser s (ReaderT s' m) (ReaderT s' p) Source # | |
(MonadParser s m p, Monoid (p ((), s', Void))) => MonadParser s (StateT s' m) (StateT s' p) Source # | |
class ParseStreamType s Source #
type StreamToken s :: * Source #
type StreamChar s :: * Source #
ParseStreamType [a] Source # | |
class (ParseStreamType s, Stream (StreamToken s) s) => ParseStream s where Source #
completeBefore :: Proxy s -> StreamToken s -> Bool Source #
tokenPayload :: Proxy s -> StreamToken s -> StreamChar s Source #
acceptToken :: StreamChar s -> s -> s Source #
ParseStream [c] Source # | |
Basic combinators
(>*>) :: Monad m => ParserT a m b -> ParserT b m c -> ParserT a m c Source #
The (+)
operator with lower priority
token :: (ParseStream s, MonadParser s m p) => p (StreamChar s) Source #
Consume a token from the Stream
following :: (ParseStream s, MonadParser s m p) => p (StreamToken s) Source #
satisfy :: forall s m p. (MonadParser s m p, ParseStream s) => (StreamChar s -> Bool) -> p (StreamChar s) Source #
Consume a token and succeed if it verifies a predicate
oneOf :: forall s t m p. (Eq (StreamChar s), Foldable t, ParseStream s, MonadParser s m p) => t (StreamChar s) -> p (StreamChar s) Source #
Parse a member of a set of values
oneOfSet :: forall s m p. (Ord (StreamChar s), ParseStream s, MonadParser s m p) => Set (StreamChar s) -> p (StreamChar s) Source #
noneOf :: (Eq (StreamChar s), Foldable t, ParseStream s, MonadParser s m p) => t (StreamChar s) -> p (StreamChar s) Source #
Parse anything but a member of a set
single :: forall s m p. (MonadParser s m p, Eq (StreamChar s), ParseStream s) => StreamChar s -> p () Source #
Consume a single fixed token or fail.
several :: (Eq (StreamChar s), Foldable t, MonadParser s m p, ParseStream s) => t (StreamChar s) -> p () Source #
Consume a structure of characters or fail
like :: (Eq (StreamChar s), MonadParser s m p, ParseStream s) => [StreamChar s] -> p () Source #
Consume a structure of characters or fail
keyword :: (Eq (StreamChar s), MonadParser s m p, Foldable t, ParseStream s) => a -> t (StreamChar s) -> p a Source #
Consume a structure of characters or fail
remaining :: MonadParser s m p => p s Source #
The remaining Stream to parse
eoi :: (MonadParser s m p, ParseStream s) => p () Source #
Succeed only at the End Of Input.
Specialized utilities
number :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char, Num n) => p n Source #
Parse a litteral decimal number
digit :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char Source #
Parse a single decimal digit
letter :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char Source #
alNum :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p Char Source #
quotedString :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => Char -> p String Source #
Parse a delimited string, using \\
as the quoting character
space :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #
Zero or more spaces
nbspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #
One or more spaces
hspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #
Zero or more horizontal spaces (no newlines)
nbhspace :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #
One or more horizontal spaces (no newlines)
eol :: (MonadParser s m p, ParseStream s, StreamChar s ~ Char) => p () Source #
The end of a line
Useful combinators
many :: MonadParser s m p => p a -> p [a] Source #
Parse zero, one or more successive occurences of a parser
many1 :: MonadParser s m p => p a -> p [a] Source #
Parse one or more successiveé occurences of a parser
sepBy :: MonadParser s m p => p a -> p b -> p [a] infixl 1 Source #
Parse zero or more successive occurences of a parser separated by occurences of a second parser.
sepBy1 :: MonadParser s m p => p a -> p b -> p [a] infixl 1 Source #
Parse one or more successive occurences of a parser separated by occurences of a second parser.
skipMany :: MonadParser s m p => p a -> p () Source #
Skip many occurences of a parser
skipMany1 :: MonadParser s m p => p a -> p () Source #
Skip multiple occurences of a parser
many' :: MonadParser s m p => p a -> p [a] Source #
Parse zero, one or more successive occurences of a parser (no backtracking)
many1' :: MonadParser s m p => p a -> p [a] Source #
Parse one or more successiveé occurences of a parser (no backtracking)
sepBy' :: MonadParser s m p => p a -> p b -> p [a] Source #
Parse zero or more successive occurences of a parser separated by occurences of a second parser (no backtracking)
sepBy1' :: MonadParser s m p => p a -> p b -> p [a] Source #
Parse one or more successive occurences of a parser separated by occurences of a second parser (no backtracking)
skipMany' :: MonadParser s m p => p a -> p () Source #
Skip many occurences of a parser (no backtracking)
skipMany1' :: MonadParser s m p => p a -> p () Source #
Skip multiple occurences of a parser (no backtracking)
chainl :: MonadParser s m p => p a -> p (a -> b -> a) -> p b -> p a Source #
Chain an operator with an initial value
chainl' :: MonadParser s m p => p a -> p (a -> b -> a) -> p b -> p a Source #
Chain an operator with an initial value (eager)
chainr :: MonadParser s m p => p a -> p (b -> a -> a) -> p b -> p a Source #
Chain an operator with an initial value and several tail values.
chainr' :: MonadParser s m p => p a -> p (b -> a -> a) -> p b -> p a Source #
Chain an operator with an initial value and several tail values.
option :: MonadParser s m p => a -> p a -> p a Source #
Try to consume a parser. Return a default value when it fails.
option' :: MonadParser s m p => a -> p a -> p a Source #
Try to consume a parser. Return a default value when it fails.
optionMaybe :: MonadParser s m p => p a -> p (Maybe a) Source #
optionMaybe' :: MonadParser s m p => p a -> p (Maybe a) Source #