-
Notifications
You must be signed in to change notification settings - Fork 2
/
FSMDrawer.hs
50 lines (38 loc) · 2.45 KB
/
FSMDrawer.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- rv-2-rka
-- xdusek21
-- Daniel Dušek
module FSMDrawer where
import Data.List (delete, head)
import Types
convertToTex (FSM s _ t i f) = documentHeading ++ renderStates ++ renderTransitions t ++ ";" ++ documentFooting where
renderStates = "\n\\node[initial,state] (" ++ show i ++ ") {$" ++ show i ++ "$};\n"
++ unlines ( map
(\state -> "\\node[state] (" ++ show state ++ ")" ++ renderNodeOrdering state ++ " {$" ++ show state ++ "$};")
(delete (head f) (delete i s))
)
++ unlines (
map
(\fs -> "\\node[state, accepting] (" ++ show fs ++ ") [below right of=" ++ show (fs-1) ++ "] {$" ++ show fs ++ "$};") f
)
renderTransitions t = "\n\\path"
++ unlines (map (\t -> renderTransitionPath t) t)
renderTransitionPath (TTransition f s t) =
"\n(" ++ show f ++ ") edge "
++ renderEdge t s
++" node {" ++ renderSymbol s ++ "} (" ++ show t ++ ")"
renderSymbol s
| (s == Epsilon) = "$\\epsilon$"
| otherwise = show s
renderEdge t s
| (mod t 2) == 0 = "[" ++ colorizeEdge s ++ "bend left=20]"
| otherwise = "[" ++ colorizeEdge s ++ "bend right]"
colorizeEdge s
| s == Epsilon = ""
| otherwise = "purple, very thick, "
renderNodeOrdering s
| ((mod s 2) == 0 && (mod s 10) /= 0) = " [right of=" ++ show (s-1) ++ "] "
| (mod s 10) == 0 = " [below left of=" ++ show (s-9) ++ "] "
| otherwise = " [right of=" ++ show (s-1) ++ "] "
{-- Extension for FSM drawing --}
documentHeading = "\\documentclass{standalone}\n\\usepackage{pgf}\n\\usepackage{tikz}\n\\usetikzlibrary{arrows,automata}\n\\usepackage[latin1]{inputenc}\n\\begin{document}\n\\begin{tikzpicture}\n[->,>=stealth',shorten >=1pt,auto,node distance=3.0cm,semithick]\\tikzstyle{every state}\n=[fill=none,draw=black,text=black]"
documentFooting = "\\end{tikzpicture}\n\\end{document}\n"