summaryrefslogtreecommitdiff
path: root/src-3.0/PGF/VisualizeTree.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-06-22 13:07:09 +0000
committeraarne <aarne@cs.chalmers.se>2008-06-22 13:07:09 +0000
commit0f0e65f706eb67e8035e9737cc4647fffe15f5f8 (patch)
treee4a5dd7d89e3465b4bdd39196722741e532dae3b /src-3.0/PGF/VisualizeTree.hs
parent25f486858fcd3bad89fda6317abe750be5d29855 (diff)
tree visualization command
Diffstat (limited to 'src-3.0/PGF/VisualizeTree.hs')
-rw-r--r--src-3.0/PGF/VisualizeTree.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src-3.0/PGF/VisualizeTree.hs b/src-3.0/PGF/VisualizeTree.hs
new file mode 100644
index 000000000..1bf4dc075
--- /dev/null
+++ b/src-3.0/PGF/VisualizeTree.hs
@@ -0,0 +1,42 @@
+----------------------------------------------------------------------
+-- |
+-- Module : VisualizeTree
+-- Maintainer : AR
+-- Stability : (stable)
+-- Portability : (portable)
+--
+-- > CVS $Date:
+-- > CVS $Author:
+-- > CVS $Revision:
+--
+-- Print a graph of an abstract syntax tree in Graphviz DOT format
+-- Based on BB's VisualizeGrammar
+-- FIXME: change this to use GF.Visualization.Graphviz,
+-- instead of rolling its own.
+-----------------------------------------------------------------------------
+
+module PGF.VisualizeTree ( visualizeTrees
+ ) where
+
+import PGF.CId (prCId)
+import PGF.Data
+
+visualizeTrees :: Bool -> [Tree] -> String
+visualizeTrees digr = unlines . map (prGraph digr . tree2graph digr)
+
+tree2graph :: Bool -> Tree -> [String]
+tree2graph digr = prf [] where
+ prf ps t = case t of
+ Fun cid trees ->
+ let (nod,lab) = prn ps cid in
+ (nod ++ " [label = " ++ lab ++ ", style = \"solid\", shape = \"plaintext\"] ;") :
+ [ pra (j:ps) nod t | (j,t) <- zip [0..] trees] ++
+ concat [prf (j:ps) t | (j,t) <- zip [0..] trees]
+ prn ps cid =
+ let lab = "\"" ++ prCId cid ++ "\""
+ in (show(show (ps :: [Int])),lab)
+ pra i nod t@(Fun cid _) = nod ++ arr ++ fst (prn i cid) ++ " [style = \"solid\"];"
+ arr = if digr then " -> " else " -- "
+
+prGraph digr ns = concat $ map (++"\n") $ [graph ++ "{\n"] ++ ns ++ ["}"] where
+ graph = if digr then "digraph" else "graph"