summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Grasp/Types.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Grasp/Types.hs b/src/Grasp/Types.hs
index 0211281..72f835a 100644
--- a/src/Grasp/Types.hs
+++ b/src/Grasp/Types.hs
@@ -11,6 +11,8 @@ import Data.Graph.Inductive.Graph( Node, LNode, LEdge, (&) )
import qualified Data.Graph.Inductive.Graph as Graph
import Data.Graph.Inductive.Tree
import Data.List
+import Data.Maybe
+import qualified Data.Map as Map
@@ -27,10 +29,21 @@ instance (Ord a, Ord b) => Eq (Gr a b) where
nodesWithName :: GraspProgram -> String -> [LNode String]
-nodesWithName g s = []
+nodesWithName g s =
+ let nodes = Graph.labNodes g
+ edges = Graph.labEdges g
+ nodeLabelMap = Map.fromList nodes
+ nameEdges = filter (\(_,_,z) -> z == "name") edges
+ specific = filter (\(_,y,_) -> fromJust (Map.lookup y nodeLabelMap) == s) nameEdges
+ nameNodes = map (\(x,_,_) -> x) specific
+ in filter (\(x,_) -> x `elem` nameNodes) nodes
+
+
+
+-- to-do
normalise :: GraspProgram -> GraspProgram
normalise g = Graph.mkGraph [] []