foldl-transduce-attoparsec-0.2.0.0: Attoparsec and foldl-transduce integration.

Safe HaskellNone
LanguageHaskell98

Control.Foldl.Transduce.Attoparsec

Synopsis

Documentation

stripParse :: (ParserInput a, Monad m) => Parser a b -> TransducerM (ExceptT (ParsingError a) m) a a b Source

Strips from the stream the prefix that matches the parser.

The parsed value becomes the return value of the TransducerM.

>>> runExcept $ L.foldM (transduceM (void (stripParse (many (A.char 'a')))) (L.generalize L.mconcat)) (map T.pack ["aa","bb"])
Right "bb"
>>> runExcept $ L.foldM (transduceM' (stripParse (many (A.char 'a'))) (L.generalize L.mconcat)) (map T.pack ["aa","aa","bb"])
Right ("aaaa","bb")
>>> runExcept $ L.foldM (transduceM' (stripParse (A.char 'z')) (L.generalize L.mconcat)) (map T.pack ["aa","aa","bb"])
Left ("aa",["'z'"],"Failed reading: satisfy")

parses :: (ParserInput a, Monad m) => Parser a b -> TransducerM (ExceptT (ParsingError a) m) a b () Source

Feeds a FoldM with the results of repeatedly applying a parser.

>>> runExcept $ L.foldM (transduceM (parses (A.decimal <* A.char ' ')) (L.generalize L.list)) (map T.pack ["1 1","1 3 77 "])
Right [1,11,3,77]

type ParsingError a = (a, [String], String) Source

A triplet of (leftovers,error contexts,error message)