diff options
Diffstat (limited to 'examples/attoparser.hs')
-rw-r--r-- | examples/attoparser.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/examples/attoparser.hs b/examples/attoparser.hs new file mode 100644 index 0000000..ddf770d --- /dev/null +++ b/examples/attoparser.hs | |||
@@ -0,0 +1,21 @@ | |||
1 | import Pipes | ||
2 | import Pipes.Text.IO (fromHandle) | ||
3 | import Pipes.Attoparsec (parsed) | ||
4 | import qualified System.IO as IO | ||
5 | |||
6 | data Test = Test { | ||
7 | a :: Int, | ||
8 | b :: Int | ||
9 | } deriving (Show) | ||
10 | |||
11 | testParser :: Parser Test | ||
12 | testParser = do | ||
13 | a <- decimal | ||
14 | space | ||
15 | b <- decimal | ||
16 | endOfLine | ||
17 | return $ Test a b | ||
18 | |||
19 | main = IO.withFile "./testfile" IO.ReadMode $ \handle -> runEffect $ | ||
20 | for test_parser (lift . print) | ||
21 | where (parsed (testParser <* endOfLine) (fromHandle handle)) \ No newline at end of file | ||