| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Text.PariPari.Combinators
Synopsis
- data Text
- void :: Functor f => f a -> f ()
- (<|>) :: Alternative f => f a -> f a -> f a
- empty :: Alternative f => f a
- optional :: Alternative f => f a -> f (Maybe a)
- data NonEmpty a = a :| [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)
- 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
- (<?>) :: MonadParser p => p a -> String -> p a
- getLine :: Parser Int
- getColumn :: Parser Int
- withPos :: MonadParser p => p a -> p (Pos, a)
- withSpan :: MonadParser p => p a -> p (Span, a)
- getRefColumn :: Parser Int
- getRefLine :: Parser Int
- withRefPos :: MonadParser p => p a -> p a
- align :: Parser ()
- indented :: Parser ()
- line :: Parser ()
- linefold :: Parser ()
- notByte :: Word8 -> Parser Word8
- anyByte :: Parser Word8
- digitByte :: Int -> Parser Word8
- asciiByte :: Parser Word8
- integer :: (Num a, MonadParser p) => p sep -> Int -> p a
- integer' :: (Num a, MonadParser p) => p sep -> Int -> p (a, Int)
- decimal :: Num a => Parser a
- octal :: Num a => Parser a
- hexadecimal :: Num a => Parser a
- digit :: Int -> Parser Word
- signed :: (Num a, MonadParser p) => p a -> p a
- fractionHex :: (Num a, MonadParser p) => p digitSep -> p (a, Int, a)
- fractionDec :: (Num a, MonadParser p) => p digitSep -> p (a, Int, a)
- char' :: Char -> Parser Char
- notChar :: Char -> Parser Char
- anyChar :: Parser Char
- alphaNumChar :: Parser Char
- digitChar :: Int -> Parser Char
- letterChar :: Parser Char
- lowerChar :: Parser Char
- upperChar :: Parser Char
- symbolChar :: Parser Char
- categoryChar :: GeneralCategory -> Parser Char
- punctuationChar :: Parser Char
- spaceChar :: Parser Char
- asciiChar :: Int -> Parser Char
- string :: Text -> Parser Text
- string' :: Text -> Parser Text
- asString :: MonadParser p => p () -> p Text
- takeBytes :: Int -> Parser ByteString
- skipChars :: Int -> Parser ()
- skipBytes :: Int -> Parser ()
- takeChars :: Int -> Parser Text
- skipCharsWhile :: (Char -> Bool) -> Parser ()
- takeCharsWhile :: (Char -> Bool) -> Parser Text
- skipBytesWhile :: (Word8 -> Bool) -> Parser ()
- takeBytesWhile :: (Word8 -> Bool) -> Parser ByteString
- skipBytesWhile1 :: (Word8 -> Bool) -> Parser ()
- takeBytesWhile1 :: (Word8 -> Bool) -> Parser ByteString
- skipCharsWhile1 :: (Char -> Bool) -> Parser ()
- takeCharsWhile1 :: (Char -> Bool) -> Parser Text
Basics
A space efficient, packed, unboxed Unicode text type.
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void valueIO action.
Examples
Replace the contents of a with unit:Maybe Int
>>>void NothingNothing>>>void (Just 3)Just ()
Replace the contents of an with unit,
resulting in an Either Int Int:Either Int '()'
>>>void (Left 8675309)Left 8675309>>>void (Right 8675309)Right ()
Replace every element of a list with unit:
>>>void [1,2,3][(),(),()]
Replace the second element of a pair with unit:
>>>void (1,2)(1,())
Discard the result of an IO action:
>>>mapM print [1,2]1 2 [(),()]>>>void $ mapM print [1,2]1 2
(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #
An associative binary operation
empty :: Alternative f => f a #
The identity of <|>
optional :: Alternative f => f a -> f (Maybe a) #
One or none.
Control.Monad.Combinators.NonEmpty
Non-empty (and non-strict) list type.
Since: base-4.9.0.0
Constructors
| a :| [a] infixr 5 |
Instances
some :: MonadPlus m => m a -> m (NonEmpty a) #
applies the parser some pp 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 one or more occurrences of endBy1 p sepp, 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 endp
should succeed at least once.
See also: skipSome, skipSomeTill.
sepBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #
parses one or more occurrences of sepBy1 p sepp, separated by
sep. Returns a non-empty list of values returned by p.
sepEndBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #
parses one or more occurrences of sepEndBy1 p sepp, separated
and optionally ended by sep. Returns a non-empty list of values returned by
p.
Control.Monad.Combinators
many :: MonadPlus m => m a -> m [a] #
applies the parser many pp 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 popen, 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 psps 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 zero or more occurrences of endBy p sepp, 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 endp zero or more times until parser
end succeeds. Returns the list of values returned by p.
See also: skipMany, skipManyTill.
option :: Alternative m => a -> m a -> m a #
sepBy :: MonadPlus m => m a -> m sep -> m [a] #
parses zero or more occurrences of sepBy p sepp, 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 zero or more occurrences of sepEndBy p sepp, separated
and optionally ended by sep. Returns a list of values returned by p.
skipMany :: MonadPlus m => m a -> m () #
applies the parser skipMany pp zero or more times, skipping
its result.
See also: manyTill, skipManyTill.
skipSome :: MonadPlus m => m a -> m () #
applies the parser skipSome pp 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 endp 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 endp one or more times
skipping results until parser end succeeds. Result parsed by end is
then returned.
PariPari
withPos :: MonadParser p => p a -> p (Pos, a) Source #
Decorate the parser result with the current position
withSpan :: MonadParser p => p a -> p (Span, a) Source #
Decoreate the parser result with the position span
getRefColumn :: Parser Int Source #
Get column number of the reference position
getRefLine :: Parser Int Source #
Get line number of the reference position
withRefPos :: MonadParser p => p a -> p a Source #
Update reference position with current position
linefold :: Parser () Source #
Parser succeeds either on the reference line or for columns greater than the current reference column
digitByte :: Int -> Parser Word8 Source #
Parse a digit byte for the given base. Bases 2 to 36 are supported.
integer :: (Num a, MonadParser p) => p sep -> Int -> p a Source #
Parse an integer of the given base. Bases 2 to 36 are supported. Digits can be separated by separator, e.g. `optional (char '_')`.
integer' :: (Num a, MonadParser p) => p sep -> Int -> p (a, Int) Source #
Parse an integer of the given base. Returns the integer and the number of digits. Bases 2 to 36 are supported. Digits can be separated by separator, e.g. `optional (char '_')`.
hexadecimal :: Num a => Parser a Source #
digit :: Int -> Parser Word Source #
Parse a single digit of the given base and return its value. Bases 2 to 36 are supported.
signed :: (Num a, MonadParser p) => p a -> p a Source #
Parse a number with a plus or minus sign.
fractionHex :: (Num a, MonadParser p) => p digitSep -> p (a, Int, a) Source #
Parse a hexadecimal fraction, returning (coefficient, 2, exponent), corresponding to coefficient * 2^exponent. Digits can be separated by separator, e.g. `optional (char '_')`.
fractionDec :: (Num a, MonadParser p) => p digitSep -> p (a, Int, a) Source #
Parse a decimal fraction, returning (coefficient, 10, exponent), corresponding to coefficient * 10^exponent. Digits can be separated by separator, e.g. `optional (char '_')`.
alphaNumChar :: Parser Char Source #
Parse an alphanumeric character, including Unicode.
digitChar :: Int -> Parser Char Source #
Parse a digit character of the given base. Bases 2 to 36 are supported.
letterChar :: Parser Char Source #
Parse a letter character, including Unicode.
symbolChar :: Parser Char Source #
Parse a symbol character, including Unicode.
categoryChar :: GeneralCategory -> Parser Char Source #
Parse a character belonging to the given Unicode category
punctuationChar :: Parser Char Source #
Parse a punctuation character, including Unicode.
asString :: MonadParser p => p () -> p Text Source #
Run the given parser but return the result as a Text string
takeBytes :: Int -> Parser ByteString Source #
Take the next n bytes and advance the position by n bytes
takeChars :: Int -> Parser Text Source #
Take the next n characters and advance the position by n characters
takeBytesWhile :: (Word8 -> Bool) -> Parser ByteString Source #
Takes bytes while predicate is true
skipBytesWhile1 :: (Word8 -> Bool) -> Parser () Source #
Skip at least one byte while predicate is true
takeBytesWhile1 :: (Word8 -> Bool) -> Parser ByteString Source #
Take at least one byte while predicate is true