Skip to content

Commit

Permalink
remove 'fast-zip' dependency. (see #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Scherer committed Feb 13, 2015
1 parent d403d0e commit 519d557
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 80 deletions.
1 change: 0 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
:repositories {"sonatype-oss-public" "https://oss.sonatype.org/content/groups/public/"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/tools.reader "0.8.13"]
[fast-zip "0.5.2"]
[potemkin "0.3.11"]]
:profiles {:dev {:dependencies [[midje "1.6.3" :exclusions [joda-time]]
[joda-time "2.7"]]
Expand Down
26 changes: 13 additions & 13 deletions src/rewrite_clj/zip.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
[rewrite-clj
[parser :as p]
[node :as node]]
[fast-zip.core :as z]
[clojure.zip :as z]
[potemkin :refer [import-vars]]))

;; ## API Facade

(import-vars
[fast-zip.core
[clojure.zip
node root]

[rewrite-clj.zip.base
Expand Down Expand Up @@ -92,17 +92,17 @@
:arglists `(quote ~arglists)})]
`(def ~sym ~base)))

(defbase right* fast-zip.core/right)
(defbase left* fast-zip.core/left)
(defbase up* fast-zip.core/up)
(defbase down* fast-zip.core/down)
(defbase next* fast-zip.core/next)
(defbase prev* fast-zip.core/prev)
(defbase rightmost* fast-zip.core/rightmost)
(defbase leftmost* fast-zip.core/leftmost)
(defbase replace* fast-zip.core/replace)
(defbase edit* fast-zip.core/edit)
(defbase remove* fast-zip.core/remove)
(defbase right* clojure.zip/right)
(defbase left* clojure.zip/left)
(defbase up* clojure.zip/up)
(defbase down* clojure.zip/down)
(defbase next* clojure.zip/next)
(defbase prev* clojure.zip/prev)
(defbase rightmost* clojure.zip/rightmost)
(defbase leftmost* clojure.zip/leftmost)
(defbase replace* clojure.zip/replace)
(defbase edit* clojure.zip/edit)
(defbase remove* clojure.zip/remove)

;; ## DEPRECATED

Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/base.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[node :as node]
[parser :as p]]
[rewrite-clj.zip.whitespace :as ws]
[fast-zip.core :as z]))
[clojure.zip :as z]))

;; ## Zipper

Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/edit.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[utils :as u]
[whitespace :as ws]]
[rewrite-clj.node :as node]
[fast-zip.core :as z]))
[clojure.zip :as z]))

;; ## In-Place Modification

Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/find.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[base :as base]
[move :as m]]
[rewrite-clj.node :as node]
[fast-zip.core :as z]))
[clojure.zip :as z]))

;; ## Helpers

Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/insert.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[base :as base]
[whitespace :as ws]]
[rewrite-clj.node :as node]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(def ^:private space
(node/spaces 1))
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/move.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns ^:no-doc rewrite-clj.zip.move
(:refer-clojure :exclude [next])
(:require [rewrite-clj.zip.whitespace :as ws]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(defn right
"Move right to next non-whitespace/non-comment location."
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/remove.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[move :as m]
[utils :as u]
[whitespace :as ws]]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(defn- remove-trailing-space
"Remove all whitespace following a given node."
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/seq.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[find :as f]
[insert :as i]
[move :as m]]
[fast-zip.core :as z]))
[clojure.zip :as z]))

;; ## Predicates

Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/subedit.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns ^:no-doc rewrite-clj.zip.subedit
(:require [rewrite-clj.zip.base :as base]
[fast-zip.core :as z]))
[clojure.zip :as z]))

;; ## Edit Scope

Expand Down
88 changes: 40 additions & 48 deletions src/rewrite_clj/zip/utils.clj
Original file line number Diff line number Diff line change
@@ -1,58 +1,26 @@
(ns ^:no-doc rewrite-clj.zip.utils
(:require [fast-zip.core :as z])
(:import [fast_zip.core ZipperPath ZipperLocation]))
(:require [clojure.zip :as z]))

;; ## Remove

(defn- update-in-path
[[node path :as loc] k f]
(let [v (get path k)]
(if (seq v)
(with-meta
[node (assoc path k (f v) :changed? true)]
(meta loc))
loc)))

(defn remove-right
"Remove right sibling of the current node (if there is one)."
[^ZipperLocation zloc]
(let [path ^ZipperPath (.path zloc)]
(if (zero? (count (.r path)))
zloc
(ZipperLocation.
(.branch? zloc)
(.children zloc)
(.make-node zloc)
(.node zloc)
(assoc path :r (clojure.core/next (.r path)) :changed? true)))))
[loc]
(update-in-path loc :r next))

(defn remove-left
"Remove left sibling of the current node (if there is one)."
[^ZipperLocation zloc]
(let [path ^ZipperPath (.path zloc)]
(if (zero? (count (.l path)))
zloc
(ZipperLocation.
(.branch? zloc)
(.children zloc)
(.make-node zloc)
(.node zloc)
(assoc path :l (pop (.l path)) :changed? true)))))

(defn remove-and-move-left
"Remove current node and move left. If current node is at the leftmost
location, returns `nil`."
[^ZipperLocation zloc]
(let [path ^ZipperPath (.path zloc)]
(when (pos? (count (.l path)))
(ZipperLocation.
(.branch? zloc)
(.children zloc)
(.make-node zloc)
(peek (.l path))
(assoc path :l (pop (.l path)) :changed? true)))))

(defn remove-and-move-right
"Remove current node and move right. If current node is at the rightmost
location, returns `nil`."
[^ZipperLocation zloc]
(let [path ^ZipperPath (.path zloc)]
(when (pos? (count (.r path)))
(ZipperLocation.
(.branch? zloc)
(.children zloc)
(.make-node zloc)
(first (.r path))
(assoc path :r (clojure.core/next (.r path)) :changed? true)))))
[loc]
(update-in-path loc :l pop))

(defn remove-right-while
"Remove elements to the right of the current zipper location as long as
Expand All @@ -75,3 +43,27 @@
(recur (remove-left zloc))
zloc)
zloc)))

;; ## Remove and Move

(defn remove-and-move-left
"Remove current node and move left. If current node is at the leftmost
location, returns `nil`."
[[_ {:keys [l] :as path} :as loc]]
(if (seq l)
(with-meta
[(peek l) (-> path
(update-in [:l] pop)
(assoc :changed? true))]
(meta loc))))

(defn remove-and-move-right
"Remove current node and move right. If current node is at the rightmost
location, returns `nil`."
[[_ {:keys [r] :as path} :as loc]]
(if (seq r)
(with-meta
[(first r) (-> path
(update-in [:r] next)
(assoc :changed? true))]
(meta loc))))
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/walk.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ^:no-doc rewrite-clj.zip.walk
(:require [fast-zip.core :as z]
(:require [clojure.zip :as z]
[rewrite-clj.zip
[subedit :refer [subedit-node]]
[move :as m]]))
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite_clj/zip/whitespace.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns ^:no-doc rewrite-clj.zip.whitespace
(:require [rewrite-clj.node :as node]
[fast-zip.core :as z]))
[clojure.zip :as z]))

;; ## Predicates

Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/regression_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[rewrite-clj
[node :as node]
[zip :as z]]
[fast-zip.core :as fz]))
[clojure.zip :as fz]))

;; ## Regression Tests for 0.3.x -> 0.4.x

Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/base_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [midje.sweet :refer :all]
[rewrite-clj.node :as node]
[rewrite-clj.zip.base :as base]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(let [n (node/forms-node
[(node/spaces 3)
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/find_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rewrite-clj.zip.find-test
(:require [midje.sweet :refer :all]
[fast-zip.core :as z]
[clojure.zip :as z]
[rewrite-clj.zip
[base :as base]
[find :as f]]))
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/insert_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[base :as base]
[move :as m]
[insert :refer :all]]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(tabular
(fact "about whitespace-aware insertion."
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/remove_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[base :as base]
[move :as m]
[remove :as r]]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(tabular
(fact "about whitespace-aware removal."
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/subedit_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[base :as base]
[move :as m]
[subedit :refer :all]]
[fast-zip.core :as z]))
[clojure.zip :as z]))

(let [root (base/of-string "[1 #{2 [3 4] 5} 6]")]
(fact "about modifying subtrees."
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/utils_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rewrite-clj.zip.utils-test
(:require [midje.sweet :refer :all]
[fast-zip.core :as z]
[clojure.zip :as z]
[rewrite-clj.zip.utils :refer :all]))

(let [loc (z/down (z/vector-zip '[a b c d]))]
Expand Down
2 changes: 1 addition & 1 deletion test/rewrite_clj/zip/whitespace_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns rewrite-clj.zip.whitespace-test
(:require [midje.sweet :refer :all]
[fast-zip.core :as z]
[clojure.zip :as z]
[rewrite-clj.node :as node]
[rewrite-clj.zip.whitespace :refer :all]))

Expand Down

0 comments on commit 519d557

Please sign in to comment.