[Haskell-cafe] Strange error when using Attoparsec and Enumerator
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 problem. 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 array-0.3.0.2 attoparsec-0.8.2.0 attoparsec-enumerator-0.2.0.2 bytestring-0.9.1.7 containers-0.4.0.0 deepseq-1.1.0.2 enumerator-0.4.2 text-0.10.0.0 transformers-0.2.2.0 -} 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: [OK] *** 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 crutc...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange error when using Attoparsec and Enumerator
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 crutc...@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 problem. 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 array-0.3.0.2 attoparsec-0.8.2.0 attoparsec-enumerator-0.2.0.2 bytestring-0.9.1.7 containers-0.4.0.0 deepseq-1.1.0.2 enumerator-0.4.2 text-0.10.0.0 transformers-0.2.2.0 -} 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: [OK] *** 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 crutc...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange error when using Attoparsec and Enumerator
Oh thank you! I can't believe the number of times I read through that code without seeing that. On Sun, Dec 5, 2010 at 12:49 PM, John Millikin jmilli...@gmail.com wrote: 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 crutc...@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 problem. 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 array-0.3.0.2 attoparsec-0.8.2.0 attoparsec-enumerator-0.2.0.2 bytestring-0.9.1.7 containers-0.4.0.0 deepseq-1.1.0.2 enumerator-0.4.2 text-0.10.0.0 transformers-0.2.2.0 -} 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: [OK] *** 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 crutc...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Crutcher Dunnavant crutc...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange error when using Attoparsec and Enumerator
On Sun, Dec 5, 2010 at 6:14 PM, Crutcher Dunnavant crutc...@gmail.com wrote: 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. Hi Crutcher, I have some enumerator debug code here: https://github.com/snapframework/snap-core/blob/8c9b7098751784b9d88dff68524ed2558c03c3d8/src/Snap/Internal/Iteratee/Debug.hs It's a little bit snap-specific (uses our debug machinery) but helps me a lot when debugging iteratee stuff. Shouldn't be hard to port. It contains a debug iteratee (which just prints its input to stdout) and an iteratee wrapper which logs its input using the Snap debug mechanism before passing it on to the wrapped iteratee. G -- Gregory Collins g...@gregorycollins.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe