summaryrefslogtreecommitdiff
path: root/Presence/NestingXML.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-29 19:27:01 -0400
committerjoe <joe@jerkface.net>2013-06-29 19:27:01 -0400
commitcff377e7d208348955c05cd4de1aa852bbfa47da (patch)
treedce17f4130a252c3d60dc150e19a238d6cabef7b /Presence/NestingXML.hs
parent8f6384317ea5d62b5234a876d6f00abe31e8c24b (diff)
NestingXML experiment
Diffstat (limited to 'Presence/NestingXML.hs')
-rw-r--r--Presence/NestingXML.hs13
1 files changed, 9 insertions, 4 deletions
diff --git a/Presence/NestingXML.hs b/Presence/NestingXML.hs
index cf4fcd93..b90d0caa 100644
--- a/Presence/NestingXML.hs
+++ b/Presence/NestingXML.hs
@@ -3,6 +3,7 @@ module NestingXML where
3import Data.Conduit 3import Data.Conduit
4import Data.XML.Types 4import Data.XML.Types
5import Control.Monad.Reader 5import Control.Monad.Reader
6-- import qualified Text.XML.Stream.Parse as Parse (content)
6 7
7type NestingXML o m a = ReaderT Int (ConduitM Event o m) a 8type NestingXML o m a = ReaderT Int (ConduitM Event o m) a
8 9
@@ -36,18 +37,21 @@ maybeXML whenNothing withJust = do
36 xml <- awaitXML 37 xml <- awaitXML
37 maybe whenNothing withJust xml 38 maybe whenNothing withJust xml
38 39
39awaitCloser :: Monad m => Int -> NestingXML o m () 40awaitCloser :: MonadIO m => Int -> NestingXML o m ()
40awaitCloser lvl = do 41awaitCloser lvl = do
41 fix $ \loop -> do 42 fix $ \loop -> do
42 awaitXML
43 lvl' <- nesting 43 lvl' <- nesting
44 when (lvl' >= lvl) loop 44 when (lvl' >= lvl) $ do
45 withXML $ \xml -> do
46 liftIO $ putStrLn $ "awaitCloser: "++show (lvl',lvl,xml)
47 loop
45 48
46nextElement :: Monad m => NestingXML o m (Maybe Event) 49nextElement :: MonadIO m => NestingXML o m (Maybe Event)
47nextElement = do 50nextElement = do
48 lvl <- nesting 51 lvl <- nesting
49 fix $ \loop -> do 52 fix $ \loop -> do
50 xml <- awaitXML 53 xml <- awaitXML
54 liftIO $ putStrLn $ "nextElement: "++show xml
51 case xml of 55 case xml of
52 Nothing -> return Nothing 56 Nothing -> return Nothing
53 Just (EventBeginElement _ _) -> return xml 57 Just (EventBeginElement _ _) -> return xml
@@ -55,3 +59,4 @@ nextElement = do
55 lvl' <- nesting 59 lvl' <- nesting
56 if (lvl'>=lvl) then loop 60 if (lvl'>=lvl) then loop
57 else return Nothing 61 else return Nothing
62