From a0c0d197659eb12f9f22a154af2af7b50c57d57f Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Sun, 27 Apr 2014 22:37:47 +1000 Subject: Added variables to node data structure --- src/Grasp/Parser.hs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Grasp/Parser.hs b/src/Grasp/Parser.hs index 4b42ab6..75f8fad 100644 --- a/src/Grasp/Parser.hs +++ b/src/Grasp/Parser.hs @@ -1,6 +1,12 @@ module Grasp.Parser ( GraspProgram(..), - parseGrasp + GraspNode, + + parseGrasp, + + getNodeLabel, + getFloat, + getString ) where @@ -13,7 +19,15 @@ import Data.Graph.Inductive.Tree -data GraspProgram = Gr String String +data GraspProgram = Gr GraspNode GraspLabel + + +data GraspNode = GFloat GraspLabel Float + | GString GraspLabel String + | GEmpty GraspLabel + + +type GraspLabel = String @@ -32,6 +46,25 @@ parseGrasp = parse grasp "error" +getNodeLabel :: GraspNode -> GraspLabel +getNodeLabel (GFloat label _) = label +getNodeLabel (GString label _) = label +getNodelabel (GEmpty label) = label + + + +getFloat :: GraspNode -> Maybe Float +getFloat (GFloat _ f) = Just f +getFloat _ = Nothing + + + +getString :: GraspNode -> Maybe String +getString (GString _ s) = Just s +getString _ = Nothing + + + grasp = do string "digraph {" -- cgit