Created
September 4, 2012 12:58
-
-
Save ordnungswidrig/3620929 to your computer and use it in GitHub Desktop.
liberator decision flow to graphviz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns doc) | |
(defn destructure | |
([_ name then else] [name then else]) | |
([_ name test then else] [name then else])) | |
(defn format-node [node] | |
(when (.startsWith (str node) "handle-") | |
(format "\"%s\" [peripheries=2];\n" node))) | |
(defn to-graph [[& args]] | |
(condp = (first args) | |
'defdecision | |
(let [[name then else] (apply destructure args)] | |
(str | |
(format-node then) | |
(format-node else) | |
(format (str "\"%s\" -> \"%s\" [label = \"true\"] \n" | |
"\"%s\" -> \"%s\" [label=\"false\"]\n") | |
name then name else))) | |
'defaction | |
(let [[_ name then] args] | |
(format "\"%s\"[shape=\"ellipse\"];\n\"%s\"-> \"%s\"\n" name name then)) | |
nil)) | |
(->> (let [pr (java.io.PushbackReader. | |
(clojure.java.io/reader "src/liberator/core.clj")) | |
eof (Object.)] | |
(take-while #(not= eof %) (repeatedly #(read pr false eof)))) | |
(map to-graph) | |
(filter identity) | |
(apply str) | |
(format "digraph {\nnode[shape=\"box\", splines=ortho]\n\"start\"[shape=circle];\n\"start\" -> \"service-available?\"\n%s\n}") | |
(println)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment