Portability | portable |
---|---|
Stability | provisional |
Maintainer | Samuel Hoffstaetter (samuel@hoffstaetter.com) |
Safe Haskell | Safe-Inferred |
Text.Parsec.Permutation is a permutation parser for parsec intended as a generalized replacement for Text.Parsec.Perm in parsec.
Example usage:
import Text.Parsec.Permutation fooParser :: ParsecT s u m a -> ParsecT s u m [a] fooParser = runPermParser $ (,,) <$> oncePerm (char 'A') <*> manyPerm (char 'B') <*> optionMaybePerm (char 'C' >> char 'D')
This parser will return (A
, "BBB", Just D
) when parsing for example
the strings "BCDABB", "CDBBAB", &etc.
- data PermParser s u m a
- runPermParser :: Stream s m t => PermParser s u m a -> ParsecT s u m a
- runPermParserTill :: Stream s m t => ParsecT s u m end -> PermParser s u m a -> ParsecT s u m a
- oncePerm :: Stream s m t => ParsecT s u m a -> PermParser s u m a
- manyPerm :: ParsecT s u m a -> PermParser s u m [a]
- many1Perm :: ParsecT s u m a -> PermParser s u m [a]
- optionPerm :: Stream s m t => a -> ParsecT s u m a -> PermParser s u m a
- optionMaybePerm :: Stream s m t => ParsecT s u m a -> PermParser s u m (Maybe a)
Documentation
data PermParser s u m a Source
Functor (PermParser s u m) | |
Stream s m t => Applicative (PermParser s u m) |
runPermParser :: Stream s m t => PermParser s u m a -> ParsecT s u m aSource
Turns a permutation parser into a regular parsec parser.
runPermParserTill :: Stream s m t => ParsecT s u m end -> PermParser s u m a -> ParsecT s u m aSource
Similar to runPermParser, but attempts parsing permutations only until the
given untilParser
succeeds (similar to manyTill
in Text.Parsec).
The text parsed by the untilParser is not consumed, however, so that its contents can be parsed later if necessary.
oncePerm :: Stream s m t => ParsecT s u m a -> PermParser s u m aSource
Attempt parsing a value once. Fails if parsing the value succeeds multiple times.
manyPerm :: ParsecT s u m a -> PermParser s u m [a]Source
Parses a given value as many times as possible in the permutation. As with Parsec.Prim.many in parsec, you need to make sure that the provided parser consumes input when succeeding to prevent infinite recursion.
many1Perm :: ParsecT s u m a -> PermParser s u m [a]Source
Same as manyPerm, but fails when the parsing doesn't succeed at least once.
optionPerm :: Stream s m t => a -> ParsecT s u m a -> PermParser s u m aSource
Attempt parsing a value at most once. Fails when parsing the value succeeds multiple times. The first argument is the default value to be used when parsing never succeeds.
optionMaybePerm :: Stream s m t => ParsecT s u m a -> PermParser s u m (Maybe a)Source
Similar to optionPerm, but uses Nothing as the default value.