Safe Haskell | None |
---|---|

Language | Haskell2010 |

## Synopsis

- void :: Functor f => f a -> f ()
- (<|>) :: Alternative f => f a -> f a -> f a
- empty :: Alternative f => f a
- some :: MonadPlus m => m a -> m (NonEmpty a)
- endBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
- someTill :: MonadPlus m => m a -> m end -> m (NonEmpty a)
- sepBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
- sepEndBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
- optional :: Alternative f => f a -> f (Maybe a)
- many :: MonadPlus m => m a -> m [a]
- between :: Applicative m => m open -> m close -> m a -> m a
- choice :: (Foldable f, Alternative m) => f (m a) -> m a
- count :: Monad m => Int -> m a -> m [a]
- count' :: MonadPlus m => Int -> Int -> m a -> m [a]
- eitherP :: Alternative m => m a -> m b -> m (Either a b)
- endBy :: MonadPlus m => m a -> m sep -> m [a]
- manyTill :: MonadPlus m => m a -> m end -> m [a]
- option :: Alternative m => a -> m a -> m a
- sepBy :: MonadPlus m => m a -> m sep -> m [a]
- sepEndBy :: MonadPlus m => m a -> m sep -> m [a]
- skipMany :: MonadPlus m => m a -> m ()
- skipSome :: MonadPlus m => m a -> m ()
- skipCount :: Monad m => Int -> m a -> m ()
- skipManyTill :: MonadPlus m => m a -> m end -> m end
- skipSomeTill :: MonadPlus m => m a -> m end -> m end
- (<?>) :: ChunkParser k p => p a -> String -> p a
- getLine :: ChunkP k Int
- getColumn :: ChunkP k Int
- withPos :: ChunkParser k p => p a -> p (Pos, a)
- withSpan :: ChunkParser k p => p a -> p (Span, a)
- getRefColumn :: ChunkP k Int
- getRefLine :: ChunkP k Int
- withRefPos :: ChunkParser k p => p a -> p a
- align :: ChunkP k ()
- indented :: ChunkP k ()
- line :: ChunkP k ()
- linefold :: ChunkP k ()
- notElement :: forall k p. ChunkParser k p => Element k -> p (Element k)
- anyElement :: ChunkP k (Element k)
- elementSatisfy :: ChunkParser k p => (Element k -> Bool) -> p (Element k)
- takeElements :: ChunkParser k p => Int -> p k
- skipElements :: ChunkParser k p => Int -> p ()
- skipElementsWhile :: ChunkParser k p => (Element k -> Bool) -> p ()
- takeElementsWhile :: ChunkParser k p => (Element k -> Bool) -> p k
- skipElementsWhile1 :: ChunkParser k p => (Element k -> Bool) -> p ()
- takeElementsWhile1 :: ChunkParser k p => (Element k -> Bool) -> p k
- scanElements :: ChunkParser k p => (s -> Element k -> Maybe s) -> s -> p s
- scanElements1 :: ChunkParser k p => (s -> Element k -> Maybe s) -> s -> p s

# Basic combinators

void :: Functor f => f a -> f () #

discards or ignores the result of evaluation, such
as the return value of an `void`

value`IO`

action.

#### Examples

Replace the contents of a

with unit:`Maybe`

`Int`

`>>>`

Nothing`void Nothing`

`>>>`

Just ()`void (Just 3)`

Replace the contents of an

with unit,
resulting in an `Either`

`Int`

`Int`

:`Either`

`Int`

'()'

`>>>`

Left 8675309`void (Left 8675309)`

`>>>`

Right ()`void (Right 8675309)`

Replace every element of a list with unit:

`>>>`

[(),(),()]`void [1,2,3]`

Replace the second element of a pair with unit:

`>>>`

(1,())`void (1,2)`

Discard the result of an `IO`

action:

`>>>`

1 2 [(),()]`mapM print [1,2]`

`>>>`

1 2`void $ mapM print [1,2]`

(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #

An associative binary operation

empty :: Alternative f => f a #

The identity of `<|>`

# Control.Monad.Combinators.NonEmpty

some :: MonadPlus m => m a -> m (NonEmpty a) #

applies the parser `some`

p`p`

*one* or more times and returns a
list of the values returned by `p`

.

word = some letter

endBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #

parses `endBy1`

p sep*one* or more occurrences of `p`

, separated and
ended by `sep`

. Returns a non-empty list of values returned by `p`

.

someTill :: MonadPlus m => m a -> m end -> m (NonEmpty a) #

works similarly to `someTill`

p end

, but `manyTill`

p end`p`

should succeed at least once.

See also: `skipSome`

, `skipSomeTill`

.

sepBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #

parses `sepBy1`

p sep*one* or more occurrences of `p`

, separated by
`sep`

. Returns a non-empty list of values returned by `p`

.

sepEndBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #

parses `sepEndBy1`

p sep*one* or more occurrences of `p`

, separated
and optionally ended by `sep`

. Returns a non-empty list of values returned by
`p`

.

# Control.Monad.Combinators

optional :: Alternative f => f a -> f (Maybe a) #

One or none.

many :: MonadPlus m => m a -> m [a] #

applies the parser `many`

p`p`

*zero* or more times and returns a
list of the values returned by `p`

.

identifier = (:) <$> letter <*> many (alphaNumChar <|> char '_')

between :: Applicative m => m open -> m close -> m a -> m a #

parses `between`

open close p`open`

, followed by `p`

and `close`

.
Returns the value returned by `p`

.

braces = between (symbol "{") (symbol "}")

choice :: (Foldable f, Alternative m) => f (m a) -> m a #

tries to apply the parsers in the list `choice`

ps`ps`

in order,
until one of them succeeds. Returns the value of the succeeding parser.

choice = asum

eitherP :: Alternative m => m a -> m b -> m (Either a b) #

Combine two alternatives.

eitherP a b = (Left <$> a) <|> (Right <$> b)

endBy :: MonadPlus m => m a -> m sep -> m [a] #

parses `endBy`

p sep*zero* or more occurrences of `p`

, separated and
ended by `sep`

. Returns a list of values returned by `p`

.

cStatements = cStatement `endBy` semicolon

manyTill :: MonadPlus m => m a -> m end -> m [a] #

applies parser `manyTill`

p end`p`

*zero* or more times until parser
`end`

succeeds. Returns the list of values returned by `p`

. **Note** that
`end`

result is consumed and lost. Use `manyTill_`

if you wish to keep
it.

See also: `skipMany`

, `skipManyTill`

.

option :: Alternative m => a -> m a -> m a #

sepBy :: MonadPlus m => m a -> m sep -> m [a] #

parses `sepBy`

p sep*zero* or more occurrences of `p`

, separated by
`sep`

. Returns a list of values returned by `p`

.

commaSep p = p `sepBy` comma

sepEndBy :: MonadPlus m => m a -> m sep -> m [a] #

parses `sepEndBy`

p sep*zero* or more occurrences of `p`

, separated
and optionally ended by `sep`

. Returns a list of values returned by `p`

.

skipMany :: MonadPlus m => m a -> m () #

applies the parser `skipMany`

p`p`

*zero* or more times, skipping
its result.

See also: `manyTill`

, `skipManyTill`

.

skipSome :: MonadPlus m => m a -> m () #

applies the parser `skipSome`

p`p`

*one* or more times, skipping its
result.

See also: `someTill`

, `skipSomeTill`

.

skipManyTill :: MonadPlus m => m a -> m end -> m end #

applies the parser `skipManyTill`

p end`p`

*zero* or more times
skipping results until parser `end`

succeeds. Result parsed by `end`

is
then returned.

skipSomeTill :: MonadPlus m => m a -> m end -> m end #

applies the parser `skipSomeTill`

p end`p`

*one* or more times
skipping results until parser `end`

succeeds. Result parsed by `end`

is
then returned.

# PariPari

withPos :: ChunkParser k p => p a -> p (Pos, a) Source #

Decorate the parser result with the current position

withSpan :: ChunkParser k p => p a -> p (Span, a) Source #

Decorate the parser result with the position span

getRefColumn :: ChunkP k Int Source #

Get column number of the reference position

getRefLine :: ChunkP k Int Source #

Get line number of the reference position

withRefPos :: ChunkParser k p => p a -> p a Source #

Update reference position with current position

indented :: ChunkP k () Source #

Parser succeeds for columns greater than the current reference column

linefold :: ChunkP k () Source #

Parser succeeds either on the reference line or for columns greater than the current reference column

notElement :: forall k p. ChunkParser k p => Element k -> p (Element k) Source #

Parser a single element different from the given one

anyElement :: ChunkP k (Element k) Source #

Parse an arbitrary element

elementSatisfy :: ChunkParser k p => (Element k -> Bool) -> p (Element k) Source #

Parse a single element with the given predicate

takeElements :: ChunkParser k p => Int -> p k Source #

Take the next n elements and advance the position by n

skipElements :: ChunkParser k p => Int -> p () Source #

Skip the next n elements

skipElementsWhile :: ChunkParser k p => (Element k -> Bool) -> p () Source #

Skip elements while predicate is true

takeElementsWhile :: ChunkParser k p => (Element k -> Bool) -> p k Source #

Takes elements while predicate is true

skipElementsWhile1 :: ChunkParser k p => (Element k -> Bool) -> p () Source #

Skip at least one element while predicate is true

takeElementsWhile1 :: ChunkParser k p => (Element k -> Bool) -> p k Source #

Take at least one element while predicate is true

scanElements :: ChunkParser k p => (s -> Element k -> Maybe s) -> s -> p s Source #

scanElements1 :: ChunkParser k p => (s -> Element k -> Maybe s) -> s -> p s Source #