i’ve wrote the following Haskell code
import Data.Attoparsec (Parser)
import qualified Data.Attoparsec.Char8 as A
import qualified Data.ByteString.Char8 as B
someWithSep sep p = A.sepBy p sep
the code is suppose to work this way :
main*> A.parse (someWithSep A.skipSpace A.decimal) $ B.pack "123 45 67 89"
Done "" [123,45,67,89]
but since I’ve defined someWithSep like in the code written above, I always get the following behavior :
main*> A.parse (someWithSep A.skipSpace A.decimal) $ B.pack "123 45 67 89"
Partial _
unless I provide a corrupted entry :
main*> A.parse (someWithSep A.skipSpace A.decimal) $ B.pack "123 45 67 89f"
Done "f" [123,45,67,89]
How can I correct this ?
thanks to reply
The
Partialconstructor doesn’t indicate failure, merely that parsing could continue if you wanted it to. You should take the Partial item and feed it the empty ByteString (as per the docs: http://hackage.haskell.org/packages/archive/attoparsec/0.8.1.0/doc/html/Data-Attoparsec-Char8.html#t:Result) to get the final result.Just to show it works:
Of course, you probably want to have a case statement in the end to handle the other cases.