An associative binary operation
Moduleparser-combinators-1.3.0Haskell2010
Control.Monad.Combinators
The module provides more efficient versions of the combinators from Control.Applicative.Combinators defined in terms of Monad and MonadPlus instead of Applicative and Alternative. When there is no difference in performance we just re-export the combinators from Control.Applicative.Combinators.
- 24 values
- Packageparser-combinators-1.3.0
- Exports26
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceCombinators.hs
Re-exports from Control.Applicative
3 declarationsThis combinator implements choice. The parser p <|> q first applies
p. If it succeeds, the value of p is returned. If p fails, parser
q is tried.
One or none.
It is useful for modelling any computation that is allowed to fail.
Examples
Using the Alternative instance of Control.Monad.Except, the following functions:
import Control.Monad.ExceptcanFail = throwError "it failed" :: Except String Intfinal = return 42 :: Except String Int
Can be combined by allowing the first function to fail:
runExcept $ canFail *> finalLeft "it failed"
runExcept $ optional canFail *> finalRight 42
optional p tries to apply the parser p. It will parse p or
Nothing. It only fails if p fails after consuming input. On success
result of p is returned inside of Just, on failure Nothing is
returned.
See also: option.
The identity of <|>
empty <|> a == a
a <|> empty == aThis parser fails unconditionally without providing any information about the cause of the failure.
Original combinators
23 declarationsbetween open close p parses open, followed by p and close.
Returns the value returned by p.
braces = between (symbol "{") (symbol "}")choice ps tries to apply the parsers in the list ps in order,
until one of them succeeds. Returns the value of the succeeding parser.
choice = asumCombine two alternatives.
eitherP a b = (Left <$> a) <|> (Right <$> b)endBy p sep parses zero or more occurrences of p, separated and
ended by sep. Returns a list of values returned by p.
cStatements = cStatement `endBy` semicolonendBy1 p sep parses one or more occurrences of p, separated and
ended by sep. Returns a list of values returned by p.
many p applies the parser p zero or more times and returns a
list of the values returned by p.
identifier = (:) <$> letter <*> many (alphaNumChar <|> char '_')manyTill p end applies parser 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.
manyTill_ p end applies parser p zero or more times until
parser end succeeds. Returns the list of values returned by p and the
end result. Use manyTill if you have no need in the result of the
end.
See also: skipMany, skipManyTill.
some p applies the parser p one or more times and returns a
list of the values returned by p.
word = some lettersomeTill p end works similarly to manyTill p end, but p
should succeed at least once. Note that end result is consumed and
lost. Use someTill_ if you wish to keep it.
someTill p end = liftM2 (:) p (manyTill p end)See also: skipSome, skipSomeTill.
someTill_ p end works similarly to manyTill_ p end, but p
should succeed at least once. Use someTill if you have no need in the
result of the end.
See also: skipSome, skipSomeTill.
sepBy p sep parses zero or more occurrences of p, separated by
sep. Returns a list of values returned by p.
commaSep p = p `sepBy` commasepBy1 p sep parses one or more occurrences of p, separated by
sep. Returns a list of values returned by p.
sepEndBy p sep parses zero or more occurrences of p, separated
and optionally ended by sep. Returns a list of values returned by p.
sepEndBy1 p sep parses one or more occurrences of p, separated
and optionally ended by sep. Returns a list of values returned by p.
skipMany p applies the parser p zero or more times, skipping
its result.
See also: manyTill, skipManyTill.
skipSome p applies the parser p one or more times, skipping its
result.
See also: someTill, skipSomeTill.
skipManyTill p end applies the parser p zero or more times
skipping results until parser end succeeds. Result parsed by end is
then returned.
skipSomeTill p end applies the parser p one or more times
skipping results until parser end succeeds. Result parsed by end is
then returned.