mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-22 09:32:53 -06:00
Fixed some bugs in the Graphviz printer.
This commit is contained in:
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/09/14 18:00:19 $
|
-- > CVS $Date: 2005/09/15 18:10:44 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: bringert $
|
||||||
-- > CVS $Revision: 1.10 $
|
-- > CVS $Revision: 1.11 $
|
||||||
--
|
--
|
||||||
-- A simple finite state network module.
|
-- A simple finite state network module.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -130,7 +130,6 @@ toGraphviz (FA (Graph _ ns es) s f) = Dot.Graph Dot.Directed [] (map mkNode ns)
|
|||||||
++ if n `elem` f then [("style","bold")] else []
|
++ if n `elem` f then [("style","bold")] else []
|
||||||
mkEdge (x,y,l) = Dot.Edge (show x) (show y) [("label",l)]
|
mkEdge (x,y,l) = Dot.Edge (show x) (show y) [("label",l)]
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- * Graphs
|
-- * Graphs
|
||||||
--
|
--
|
||||||
|
|||||||
@@ -5,9 +5,9 @@
|
|||||||
-- Stability : (stable)
|
-- Stability : (stable)
|
||||||
-- Portability : (portable)
|
-- Portability : (portable)
|
||||||
--
|
--
|
||||||
-- > CVS $Date: 2005/09/14 15:17:30 $
|
-- > CVS $Date: 2005/09/15 18:10:44 $
|
||||||
-- > CVS $Author: bringert $
|
-- > CVS $Author: bringert $
|
||||||
-- > CVS $Revision: 1.1 $
|
-- > CVS $Revision: 1.2 $
|
||||||
--
|
--
|
||||||
-- Graphviz DOT format representation and printing.
|
-- Graphviz DOT format representation and printing.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
@@ -19,6 +19,8 @@ module GF.Visualization.Graphviz (
|
|||||||
prGraphviz
|
prGraphviz
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Data.Char
|
||||||
|
|
||||||
import GF.Data.Utilities
|
import GF.Data.Utilities
|
||||||
|
|
||||||
data Graph = Graph GraphType [Attr] [Node] [Edge]
|
data Graph = Graph GraphType [Attr] [Node] [Edge]
|
||||||
@@ -51,18 +53,29 @@ prNode :: Node -> String
|
|||||||
prNode (Node n at) = esc n ++ " " ++ prAttrList at
|
prNode (Node n at) = esc n ++ " " ++ prAttrList at
|
||||||
|
|
||||||
prEdge :: GraphType -> Edge -> String
|
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 :: GraphType -> String
|
||||||
edgeop Directed = "->"
|
edgeop Directed = "->"
|
||||||
edgeop Undirected = "--"
|
edgeop Undirected = "--"
|
||||||
|
|
||||||
prAttrList :: [Attr] -> String
|
prAttrList :: [Attr] -> String
|
||||||
prAttrList = join "," . map prAttr
|
prAttrList [] = ""
|
||||||
|
prAttrList at = "[" ++ join "," (map prAttr at) ++ "]"
|
||||||
|
|
||||||
prAttr :: Attr -> String
|
prAttr :: Attr -> String
|
||||||
prAttr (n,v) = esc n ++ " = " ++ esc v
|
prAttr (n,v) = esc n ++ " = " ++ esc v
|
||||||
|
|
||||||
esc :: String -> String
|
esc :: String -> String
|
||||||
esc s = "\"" ++ concat [ if shouldEsc c then ['\\',c] else [c] | c <- s ] ++ "\""
|
esc s | needEsc s = "\"" ++ concat [ if shouldEsc c then ['\\',c] else [c] | c <- s ] ++ "\""
|
||||||
|
| otherwise = s
|
||||||
where shouldEsc = (`elem` ['"', '\\'])
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user