Skip to content

Commit

Permalink
Stub for streaming parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbe committed Oct 1, 2012
1 parent d13767d commit 30ec6d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Data/Csv/Streaming.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Data.Csv.Streaming
( decode
, Result(..)
) where

import qualified Data.Attoparsec as A
import qualified Data.ByteString as B

import Data.Csv.Conversion hiding (Result)
import Data.Csv.Parser

data Result a = Some [a] (B.ByteString -> Result a)
| Partial (B.ByteString -> Result a)
| Fail B.ByteString String -- TODO: add more failure info

decode :: FromRecord a => B.ByteString -> Result a
decode = go
where
go s = case A.parse (csv defaultDecodeOptions) s of
A.Fail rest _ msg -> Fail rest $ "parse error (" ++ msg ++ ")"
A.Partial k -> Partial go
A.Done rest r -> Some undefined undefined
1 change: 1 addition & 0 deletions cassava.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Extra-source-files: examples/*.hs
Library
Exposed-modules: Data.Csv
Data.Csv.Parser
Data.Csv.Streaming

Other-modules: Data.Csv.Compat.Monoid
Data.Csv.Conversion
Expand Down

0 comments on commit 30ec6d2

Please sign in to comment.