Skip to content

Commit

Permalink
Preparing to add node as metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mrb committed May 9, 2013
1 parent 546b20c commit 29a14a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions examples/examples.clj
Expand Up @@ -45,8 +45,8 @@

(get-duplicate-method-names ruby-code)

(def o
(let [writer (StringWriter.)
node (-> (ruby-code-zipper ruby-code) z/next z/next first)]
(.accept node (ReWriteVisitor. writer "(string)"))
writer))
(ruby-code-zipper ruby-code)

(zipper-to-source (ruby-code-zipper ruby-code))

(parse-ruby-code ruby-code)
15 changes: 10 additions & 5 deletions src/graaaph/core.clj
Expand Up @@ -98,10 +98,11 @@
[:end-offset (.getEndOffset position)]])))

(defn data-visitor [node-list]
(let [node (first node-list)]
(let [node (first node-list)
node-map {}]
(if (and (not (nil? node))
(not (invalid-ast-node? node)))
(into {}
(into node-map
[[:type (-> node .getNodeType str)]
[:value (if (value-node? node)
(.getValue node))]
Expand Down Expand Up @@ -142,9 +143,13 @@
(let [zipper (first (ruby-code-zipper ruby-code))]
(v/view-tree can-have-children? get-children zipper
:options {:dpi 50}
:node->descriptor (fn [node] {:shape (cond (named-node? node) "rectangle")
:label (cond (named-node? node) (str (.getName node) " (" (str (.getNodeType node)) ")")
:else (str (.getNodeType node)))}))))
:node->descriptor (fn [node] {:shape
(cond
(named-node? node) "rectangle")
:label
(cond
(named-node? node) (str (.getName node) " (" (str (.getNodeType node)) ")")
:else (str (.getNodeType node)))}))))

(defn save-ruby-ast-image [ruby-code filename]
(let [zipper (first (ruby-code-zipper ruby-code))
Expand Down

0 comments on commit 29a14a3

Please sign in to comment.