diff options
author | joe <joe@jerkface.net> | 2013-06-29 19:27:01 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-06-29 19:27:01 -0400 |
commit | cff377e7d208348955c05cd4de1aa852bbfa47da (patch) | |
tree | dce17f4130a252c3d60dc150e19a238d6cabef7b /Presence/NestingXML.hs | |
parent | 8f6384317ea5d62b5234a876d6f00abe31e8c24b (diff) |
NestingXML experiment
Diffstat (limited to 'Presence/NestingXML.hs')
-rw-r--r-- | Presence/NestingXML.hs | 13 |
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 | |||
3 | import Data.Conduit | 3 | import Data.Conduit |
4 | import Data.XML.Types | 4 | import Data.XML.Types |
5 | import Control.Monad.Reader | 5 | import Control.Monad.Reader |
6 | -- import qualified Text.XML.Stream.Parse as Parse (content) | ||
6 | 7 | ||
7 | type NestingXML o m a = ReaderT Int (ConduitM Event o m) a | 8 | type 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 | ||
39 | awaitCloser :: Monad m => Int -> NestingXML o m () | 40 | awaitCloser :: MonadIO m => Int -> NestingXML o m () |
40 | awaitCloser lvl = do | 41 | awaitCloser 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 | ||
46 | nextElement :: Monad m => NestingXML o m (Maybe Event) | 49 | nextElement :: MonadIO m => NestingXML o m (Maybe Event) |
47 | nextElement = do | 50 | nextElement = 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 | |||