Portability | non-portable (GNTD, DeriveFunctor, OverloadedStrings) |
---|---|
Stability | experimental |
Maintainer | hans@hanshoglund.se |
Safe Haskell | None |
Lightweight parsing library based on partial functions.
- data SparserT s a b
- type Sparser = SparserT () Char
- asSparser :: Sparser a -> Sparser a
- runSparser :: Sparser a -> String -> Maybe a
- runSparserT :: SparserT s a b -> s -> [a] -> Maybe b
- runSparserT' :: SparserT s a b -> s -> [a] -> Maybe (s, [a], b)
- withState :: (s -> t) -> (t -> s) -> SparserT t a b -> SparserT s a b
- stateP :: SparserT s a s
- headP :: (s -> a -> Bool) -> SparserT s a a
- splitP :: (s -> [a] -> Int) -> SparserT s a [a]
- gateP :: (s -> [a] -> Bool) -> SparserT s a ()
- atEnd :: SparserT s a ()
- char :: Eq a => a -> SparserT s a a
- notChar :: Eq a => a -> SparserT s a a
- charIf :: (a -> Bool) -> SparserT s a a
- string :: Eq a => [a] -> SparserT s a [a]
- stringIf :: Int -> ([a] -> Bool) -> SparserT s a [a]
- space :: SparserT s Char [Char]
- integer :: SparserT s Char Integer
- stringLiteral :: SparserT s Char String
- brackets :: SparserT s Char b -> SparserT s Char b
- braces :: SparserT s Char b -> SparserT s Char b
- complete :: SparserT s a b -> SparserT s a b
- ifState :: (s -> Bool) -> SparserT s a b -> SparserT s a b
- between :: Monad m => m a -> m a1 -> m b -> m b
- skipMany1 :: (Monad m, Alternative m) => m a -> m ()
- skipMany :: (Monad f, Alternative f) => f a -> f ()
- many1 :: (Monad m, Alternative m) => m a -> m [a]
- sepBy :: (Monad f, Alternative f) => f a1 -> f a -> f [a1]
- sepBy1 :: (Monad m, Alternative m) => m a1 -> m a -> m [a1]
- sepEndBy1 :: (Monad m, Alternative m) => m a1 -> m a -> m [a1]
- sepEndBy :: (Monad m, Alternative m) => m a1 -> m a -> m [a1]
- endBy1 :: (Monad m, Alternative m) => m a -> m a1 -> m [a]
- endBy :: (Monad f, Alternative f) => f a -> f a1 -> f [a]
- count :: Monad m => Int -> m a -> m [a]
Sparser
Running
runSparser :: Sparser a -> String -> Maybe aSource
Run a parser, returning the result.
runSparserT :: SparserT s a b -> s -> [a] -> Maybe bSource
Run a parser with a custom state, returning the result.
runSparserT' :: SparserT s a b -> s -> [a] -> Maybe (s, [a], b)Source
Run a parser with a custom state.
This is the most general way to run a parser. It returns the final state, remaining input and the result.
Primitives
headP :: (s -> a -> Bool) -> SparserT s a aSource
Consumes one input element.
Fails if the predicate fails, or if there is no more input.
splitP :: (s -> [a] -> Int) -> SparserT s a [a]Source
Consume one or more input elements.
The given function receives the entire remaining input, and must return the number of consumed elements.
Fails if the predicate return 0 or less, or if there is no more input.
gateP :: (s -> [a] -> Bool) -> SparserT s a ()Source
Succeed based on predicate, but do not consume input.
The given function receives the entire remaining input.
Basic parsers
Combinators
skipMany1 :: (Monad m, Alternative m) => m a -> m ()Source
skipMany :: (Monad f, Alternative f) => f a -> f ()Source
many1 :: (Monad m, Alternative m) => m a -> m [a]Source
sepBy :: (Monad f, Alternative f) => f a1 -> f a -> f [a1]Source
sepBy1 :: (Monad m, Alternative m) => m a1 -> m a -> m [a1]Source
sepEndBy1 :: (Monad m, Alternative m) => m a1 -> m a -> m [a1]Source
sepEndBy :: (Monad m, Alternative m) => m a1 -> m a -> m [a1]Source
endBy1 :: (Monad m, Alternative m) => m a -> m a1 -> m [a]Source
endBy :: (Monad f, Alternative f) => f a -> f a1 -> f [a]Source