diff options
| author | bringert <unknown> | 2005-09-15 17:10:44 +0000 |
|---|---|---|
| committer | bringert <unknown> | 2005-09-15 17:10:44 +0000 |
| commit | 5171e7d384d45196c09bc49be6f9ce6c5b279bab (patch) | |
| tree | f88b022dad0487374edd51d67c5a921266a1af0c /src/GF/Visualization/Graphviz.hs | |
| parent | 989fb2e4d37f77171ffa0a27c6d92826985118e8 (diff) | |
Fixed some bugs in the Graphviz printer.
Diffstat (limited to 'src/GF/Visualization/Graphviz.hs')
| -rw-r--r-- | src/GF/Visualization/Graphviz.hs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/GF/Visualization/Graphviz.hs b/src/GF/Visualization/Graphviz.hs index fe2dd0b82..a98899b81 100644 --- a/src/GF/Visualization/Graphviz.hs +++ b/src/GF/Visualization/Graphviz.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/09/14 15:17:30 $ +-- > CVS $Date: 2005/09/15 18:10:44 $ -- > CVS $Author: bringert $ --- > CVS $Revision: 1.1 $ +-- > CVS $Revision: 1.2 $ -- -- Graphviz DOT format representation and printing. ----------------------------------------------------------------------------- @@ -19,6 +19,8 @@ module GF.Visualization.Graphviz ( prGraphviz ) where +import Data.Char + import GF.Data.Utilities data Graph = Graph GraphType [Attr] [Node] [Edge] @@ -51,18 +53,29 @@ prNode :: Node -> String prNode (Node n at) = esc n ++ " " ++ prAttrList at prEdge :: GraphType -> Edge -> String -prEdge t (Edge x y at) = esc x ++ " " ++ edgeop t ++ " " ++ prAttrList at +prEdge t (Edge x y at) = esc x ++ " " ++ edgeop t ++ " " ++ esc y ++ " " ++ prAttrList at edgeop :: GraphType -> String edgeop Directed = "->" edgeop Undirected = "--" prAttrList :: [Attr] -> String -prAttrList = join "," . map prAttr +prAttrList [] = "" +prAttrList at = "[" ++ join "," (map prAttr at) ++ "]" prAttr :: Attr -> String prAttr (n,v) = esc n ++ " = " ++ esc v esc :: String -> String -esc s = "\"" ++ concat [ if shouldEsc c then ['\\',c] else [c] | c <- s ] ++ "\"" - where shouldEsc = (`elem` ['"', '\\'])
\ No newline at end of file +esc s | needEsc s = "\"" ++ concat [ if shouldEsc c then ['\\',c] else [c] | c <- s ] ++ "\"" + | otherwise = s + where shouldEsc = (`elem` ['"', '\\']) + +needEsc :: String -> Bool +needEsc [] = True +needEsc xs | all isDigit xs = False +needEsc (x:xs) = not (isIDFirst x && all isIDChar xs) + +isIDFirst, isIDChar :: Char -> Bool +isIDFirst c = c `elem` (['_']++['a'..'z']++['A'..'Z']) +isIDChar c = isIDFirst c || isDigit c |
