Skip to content

Commit 303af09

Browse files
author
Yannick Scherer
committed
Adapted Example to current library state.
1 parent fc5e572 commit 303af09

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

examples/rewrite_clj/cljx.clj

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
(defn- replace-with-spaces
3939
"Replace the given reader macro node with spaces."
4040
[zloc]
41-
(let [w (count (with-out-str (prn/print-edn (z/node zloc))))]
41+
(let [w (prn/estimate-length (z/node zloc))]
4242
(-> zloc (z/prepend-space w) z/remove)))
4343

4444
(defn- remove-reader-macro
@@ -63,24 +63,21 @@
6363

6464
(defn cljx-walk
6565
"Replace all occurences of profile reader macros."
66-
[active-profiles root]
66+
[root active-profiles]
6767
(loop [loc root]
6868
(if-let [mloc (z/find loc z/next cljx-macro?)]
6969
(recur (handle-reader-macro active-profiles mloc))
7070
loc)))
7171

7272
;; ## Test
7373

74-
(comment
75-
(def data
76-
(z/edn
77-
(p/parse-string
78-
"(defn my-inc\n [x]\n #+debug (println \"inc: x =\" x #-nomark \"[debug]\")\n (+ x 1))")))
74+
(defn run-cljx-test
75+
[profiles]
76+
(let [data (z/of-string ";; Test it!\n(defn my-inc\n [x]\n #+debug (println \"inc: x =\" x #-nomark \"[debug]\")\n (+ x 1))")]
77+
(println "Original Code:")
78+
(z/print-root data)
79+
(println "\n")
7980

80-
(println "Original Code:")
81-
(-> data z/root prn/print-edn)
82-
(println "\n")
83-
84-
(println "Processed Code:")
85-
(-> (cljx-walk #{"debug" "nomark"} data) z/root prn/print-edn)
86-
(println))
81+
(println "Processed Code:")
82+
(-> data (cljx-walk (or profiles #{"debug" "nomark"})) z/print-root)
83+
(println)))

0 commit comments

Comments
 (0)