[Haskell-cafe] Strange error when using Attoparsec and Enumerator
jmillikin at gmail.com
Sun Dec 5 21:49:02 CET 2010
I swear attoparsec-enumerator is going to give me grey hair; the error
you're receiving is because iterParser itself is divergent. Fixed in
0.2.0.3, with my sincere apologies.
On Sun, Dec 5, 2010 at 09:14, Crutcher Dunnavant <crutcher at gmail.com> wrote:
> I have spent a good chunk of the past week tracing code, trying to
> solve this problem. I'm seeing an error when using Enumerator and
> Attoparsec that I can't explain. This is a reduced form of the
> In general, I've observed that debugging broken iterators and
> enumerators is very hard. We probably want some tooling around that;
> I'm looking at an identity enumeratee with debug.trace shoved in, or
> something like that, not sure yet what would help.
> Haskell 2010, ghc 6.12.3
> import Control.Applicative ((<|>))
> import qualified Data.Attoparsec.Char8 as AP
> import qualified Data.Attoparsec.Combinator as APC
> import qualified Data.Attoparsec.Enumerator as APE
> import qualified Data.ByteString.Char8 as B
> import qualified Data.Enumerator as E
> import Data.Enumerator (($$))
> import System.IO as IO
> parseLine :: AP.Parser B.ByteString
> parseLine = do
> AP.char '+'
> return . B.pack =<< APC.manyTill AP.anyChar endOfLineOrInput
> endOfLineOrInput :: AP.Parser ()
> endOfLineOrInput = AP.endOfInput <|> AP.endOfLine
> pp :: Show a => AP.Parser a -> String -> IO ()
> pp p s = do
> result <- E.run $
> E.enumList 1 [ B.pack s ]
> $$ E.sequence (APE.iterParser p)
> $$ E.printChunks False
> case result of
> (Right _) -> return ()
> (Left e) -> IO.hPutStrLn stderr $ show e
> main = pp parseLine "+OK"
> Observed output:
> *** Exception: enumEOF: divergent iteratee
> Problems with this:
> 1) I didn't write an iteratee, enumerator, or enumeratee in this code.
> Something's wrong.
> 2) If the parser is divergent, I _should_ be getting the error message:
> "iterParser: divergent parser"
> Crutcher Dunnavant <crutcher at gmail.com>
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe