]> git.immae.eu Git - github/fretlink/text-pipes.git/blame - examples/attoparser.hs
encoding documentation
[github/fretlink/text-pipes.git] / examples / attoparser.hs
CommitLineData
955edd33 1import Pipes
2import Pipes.Text.IO (fromHandle)
3import Pipes.Attoparsec (parsed)
4import qualified System.IO as IO
8197d6e0 5import Data.Attoparsec.Text
6import Control.Applicative
955edd33 7data Test = Test {
8 a :: Int,
9 b :: Int
10 } deriving (Show)
11
12testParser :: Parser Test
13testParser = do
14 a <- decimal
15 space
16 b <- decimal
17 endOfLine
18 return $ Test a b
19
20main = IO.withFile "./testfile" IO.ReadMode $ \handle -> runEffect $
edd8726a 21 do leftover <- for (parsed testParser (fromHandle handle))
22 (lift . print)
23 return () -- ignore unparsed material
24
8197d6e0 25-- >>> :! cat testfile
26-- 1 1
27-- 2 2
28-- 3 3
29-- 4 4
30-- 5 5
31-- 6 6
32-- 7 7
33-- 8 8
34-- 9 9
35-- 10 10
36
37-- >>> main
38-- Test {a = 1, b = 1}
39-- Test {a = 2, b = 2}
40-- Test {a = 3, b = 3}
41-- Test {a = 4, b = 4}
42-- Test {a = 5, b = 5}
43-- Test {a = 6, b = 6}
44-- Test {a = 7, b = 7}
45-- Test {a = 8, b = 8}
46-- Test {a = 9, b = 9}
47-- Test {a = 10, b = 10}
48
49