diff options
Diffstat (limited to 'examples/attoparser.hs')
-rw-r--r-- | examples/attoparser.hs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/examples/attoparser.hs b/examples/attoparser.hs index ddf770d..6328991 100644 --- a/examples/attoparser.hs +++ b/examples/attoparser.hs | |||
@@ -2,7 +2,8 @@ import Pipes | |||
2 | import Pipes.Text.IO (fromHandle) | 2 | import Pipes.Text.IO (fromHandle) |
3 | import Pipes.Attoparsec (parsed) | 3 | import Pipes.Attoparsec (parsed) |
4 | import qualified System.IO as IO | 4 | import qualified System.IO as IO |
5 | 5 | import Data.Attoparsec.Text | |
6 | import Control.Applicative | ||
6 | data Test = Test { | 7 | data Test = Test { |
7 | a :: Int, | 8 | a :: Int, |
8 | b :: Int | 9 | b :: Int |
@@ -17,5 +18,32 @@ testParser = do | |||
17 | return $ Test a b | 18 | return $ Test a b |
18 | 19 | ||
19 | main = IO.withFile "./testfile" IO.ReadMode $ \handle -> runEffect $ | 20 | main = IO.withFile "./testfile" IO.ReadMode $ \handle -> runEffect $ |
20 | for test_parser (lift . print) | 21 | for (parsed testParser (fromHandle handle)) |
21 | where (parsed (testParser <* endOfLine) (fromHandle handle)) \ No newline at end of file | 22 | (lift . print) |
23 | |||
24 | |||
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 | |||