diff options
author | Marvin Borner | 2022-03-03 15:53:31 +0100 |
---|---|---|
committer | Marvin Borner | 2022-03-03 15:53:31 +0100 |
commit | 65293eedaf3469bb0f4a0b174cd53bb89c762ff5 (patch) | |
tree | a59a8d2e4dfe2a0ecbe690d7cf2877eb9451e741 /src/Fun | |
parent | e2f68d48010a17e193dcf828b907ff54bca31f00 (diff) |
Nodes (for future maybe, will remove)
Diffstat (limited to 'src/Fun')
-rw-r--r-- | src/Fun/Tree.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Fun/Tree.hs b/src/Fun/Tree.hs index 354677d..5de4695 100644 --- a/src/Fun/Tree.hs +++ b/src/Fun/Tree.hs @@ -36,3 +36,36 @@ data FunctionBody = FunctionBody [FunctionBodyElement] deriving Show data FunctionBodyElement = Statement String | FunctionBodyIdentifier String | FunctionBodyParameter String | FunctionBodyString String | FunctionBodyNumber Integer deriving Show + +---- + +data NodeValue = NodeName String | FunctionBlockNode FunctionBlock -- | Type, Lambda, .. (TODO) + deriving Show +data EmptyValue = EmptyValue + deriving Show +data Node = EmptyNode | Node NodeValue [Node] + deriving Show +data Crumb = Crumb NodeValue [Node] [Node] + deriving Show +type Zipper = (Node, [Crumb]) + +(-:) :: Maybe Zipper -> (Maybe Zipper -> Maybe Zipper) -> Maybe Zipper +u -: f = f u + +nodePred :: (NodeValue -> Bool) -> Node -> Bool +nodePred pred (Node value _) = pred value +nodePred _ _ = False + +-- One layer search from top +treeTo :: (NodeValue -> Bool) -> Maybe Zipper -> Maybe Zipper +treeTo _ Nothing = Nothing +treeTo pred (Just (EmptyNode, _)) = Nothing +treeTo pred (Just (Node value nodes, bs)) = + let (ls, node : rs) = break (nodePred pred) nodes + in Just (node, Crumb value ls rs : bs) + +treeUp :: Maybe Zipper -> Maybe Zipper +treeUp Nothing = Nothing +treeUp (Just (EmptyNode, _)) = Nothing +treeUp (Just (node, Crumb value ls rs : bs)) = + Just (Node value (ls ++ [node] ++ rs), bs) |