summaryrefslogtreecommitdiffstats
path: root/TreeSearch.hs
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-12-25 03:48:26 +0100
committertv <tv@shackspace.de>2014-12-25 03:48:26 +0100
commite4b5558bfed7d0428707bb7859a1afd41d3eef23 (patch)
treefa77abad8cd6e9236fd07c5bf98db49a18aa7e53 /TreeSearch.hs
parent2d3088c15975ed129fa12e779769396b1ede2883 (diff)
use rosezipper as cursor
Diffstat (limited to 'TreeSearch.hs')
-rw-r--r--TreeSearch.hs32
1 files changed, 31 insertions, 1 deletions
diff --git a/TreeSearch.hs b/TreeSearch.hs
index 938b076..51d65c2 100644
--- a/TreeSearch.hs
+++ b/TreeSearch.hs
@@ -14,6 +14,36 @@ depthFirst loc = case firstChild loc of
Just x -> Just x
Nothing -> case next loc of
Just x -> Just x
+ Nothing -> parentWithNext loc
+ where
+ parentWithNext x =
+ case parent x of
+ Nothing -> Nothing
+ Just x' -> case next x' of
+ Just x' -> Just x'
+ Nothing -> parentWithNext x'
+
+
+findNext :: TreePos Full a -> Maybe (TreePos Full a)
+findNext = depthFirst
+
+
+findPrev :: TreePos Full a -> Maybe (TreePos Full a)
+findPrev loc =
+ case prev loc of
+ Just x -> trans_lastChild x
Nothing -> case parent loc of
- Just x -> next x
+ Just x -> Just x
Nothing -> Nothing
+ where
+ trans_lastChild x =
+ case lastChild x of
+ Nothing -> Just x
+ Just x' -> trans_lastChild x'
+
+
+findParent :: (a -> Bool) -> TreePos Full a -> Maybe (TreePos Full a)
+findParent p loc =
+ if p (label loc)
+ then Just loc
+ else parent loc >>= findParent p