Browse files

translate-zipper moved

  • Loading branch information...
1 parent 0456339 commit 0be9fa0921a38f6aa79c7df1ecca851348ece18d @marick committed Jan 26, 2013
View
4 src/midje/parsing/0_to_fact_form/tabular.clj
@@ -1,10 +1,10 @@
(ns ^{:doc "A way to create multiple facts with the same template, but different data points."}
midje.parsing.0-to-fact-form.tabular
- (:use [clojure.string :only [join]]
+ (:use [midje.parsing.util.zip]
+ [clojure.string :only [join]]
[clojure.algo.monads :only [domonad]]
[midje.error-handling.validation-errors :only [simple-validation-error-report-form validate-m validate]]
[midje.parsing.util.file-position :only [form-with-copied-line-numbers]]
- [midje.util.form-utils :only [translate-zipper]]
[midje.emission.deprecation :only [deprecate]]
[midje.parsing.util.zip :only [skip-to-rightmost-leaf]]
[midje.parsing.1-to-explicit-form.expects :only [expect?]]
View
3 src/midje/parsing/1_to_explicit_form/background.clj
@@ -2,13 +2,14 @@
prerequisites that pertain to a group of facts."}
midje.parsing.1-to-explicit-form.background
(:use midje.clojure.core
+ midje.parsing.util.zip
[midje.parsing.util.arrows :only [start-of-checking-arrow-sequence? take-arrow-sequence]]
[midje.parsing.1-to-explicit-form.metaconstants :only [predefine-metaconstants-from-form]]
[midje.parsing.1-to-explicit-form.prerequisites :only [metaconstant-prerequisite? prerequisite-to-fake]]
[midje.data.prerequisite-state :only [with-installed-fakes]]
[midje.parsing.util.wrapping :only [for-wrapping-target? with-wrapping-target]]
[midje.util.form-utils :only [first-named? pred-cond
- symbol-named? translate-zipper]]
+ symbol-named?]]
[midje.util.laziness :only [eagerly]]
[midje.util.thread-safe-var-nesting :only [namespace-values-inside-out
with-pushed-namespace-values]])
View
4 src/midje/parsing/1_to_explicit_form/facts.clj
@@ -2,6 +2,8 @@
midje.parsing.1-to-explicit-form.facts
(:use midje.clojure.core
midje.parsing.util.core
+ midje.parsing.util.zip
+
[midje.error-handling.validation-errors :only [validate when-valid]]
[midje.parsing.1-to-explicit-form.expects :only [expect?
@@ -20,7 +22,7 @@
against-background-facts-and-checks-wrappers
against-background?]]
[midje.parsing.1-to-explicit-form.metaconstants :only [predefine-metaconstants-from-form]]
- [midje.util.form-utils :only [def-many-methods first-named? translate-zipper
+ [midje.util.form-utils :only [def-many-methods first-named?
preserve-type quoted? pred-cond reader-line-number]]
[midje.util.laziness :only [eagerly]]
[midje.parsing.util.zip :only [skip-to-rightmost-leaf]]
View
3 src/midje/parsing/2_to_lexical_maps/examples.clj
@@ -2,11 +2,12 @@
midje.parsing.2-to-lexical-maps.examples
(:use midje.clojure.core
midje.parsing.util.core
+ midje.parsing.util.zip
[midje.util.object-utils :only [object-name]]
[midje.checkers :only [exactly]]
[midje.checking.checkers.defining :only [checker? checker-makers]]
[midje.parsing.1-to-explicit-form.expects :only [expect? up-to-full-expect-form]]
- [midje.util.form-utils :only [first-named? translate-zipper map-difference
+ [midje.util.form-utils :only [first-named? map-difference
pred-cond
quoted-list-form?
def-many-methods ]]
View
3 src/midje/parsing/2_to_lexical_maps/fakes.clj
@@ -1,11 +1,12 @@
(ns ^{:doc "An intermediate stage in the compilation of prerequisites."}
midje.parsing.2-to-lexical-maps.fakes
(:use midje.clojure.core
+ midje.parsing.util.zip
[midje.util.object-utils :only [object-name]]
[midje.checkers :only [exactly]]
[midje.checking.checkers.defining :only [checker? checker-makers]]
[midje.parsing.1-to-explicit-form.expects :only [expect? up-to-full-expect-form]]
- [midje.util.form-utils :only [first-named? translate-zipper map-difference
+ [midje.util.form-utils :only [first-named? map-difference
pred-cond
quoted-list-form?]]
[midje.checking.extended-equality :only [extended-= extended-list-=]]
View
16 src/midje/parsing/2_to_lexical_maps/folded_fakes.clj
@@ -1,16 +1,12 @@
(ns ^{:doc "Unfolding prerequisites like `(f (g 1)) => 3`"}
midje.parsing.2-to-lexical-maps.folded-fakes
- (:use
- [midje.util.form-utils :only [translate-zipper map-difference
- pred-cond]]
- [midje.checking.checkers.defining :only [checker? checker-makers]]
- )
- (:require
- [clojure.zip :as zip]
+ (:use midje.parsing.util.zip
+ [midje.util.form-utils :only [map-difference
+ pred-cond]]
+ [midje.checking.checkers.defining :only [checker? checker-makers]])
+ (:require [clojure.zip :as zip]
[midje.parsing.1-to-explicit-form.expects :as expects]
- [midje.parsing.util.fnref :as fnref]
- )
- )
+ [midje.parsing.util.fnref :as fnref]))
;; Note that unfolding is done after prerequisites are converted to fakes.
View
3 src/midje/parsing/util/core.clj
@@ -1,7 +1,6 @@
(ns ^{:doc "Utility functions dealing with checking or tranforming forms or zippers."}
midje.parsing.util.core
- (:use midje.clojure.core
- [utilize.seq :only (first-truthy-fn)])
+ (:use midje.clojure.core)
(:require [clojure.zip :as zip]))
View
3 src/midje/parsing/util/file_position.clj
@@ -1,9 +1,10 @@
(ns ^{:doc "Functions to help in finding the lines you care about."}
midje.parsing.util.file-position
(:use midje.parsing.util.core
+ midje.parsing.util.zip
[clojure.string :only [split]]
[midje.parsing.util.zip :only [skip-to-rightmost-leaf]]
- [midje.util.form-utils :only [quoted? translate-zipper]]
+ [midje.util.form-utils :only [quoted?]]
[midje.parsing.util.arrows :only [all-arrows at-arrow__add-key-value-to-end__no-movement]])
(:require [clojure.zip :as zip]))
View
15 src/midje/parsing/util/zip.clj
@@ -1,7 +1,20 @@
(ns ^{:doc "Zipper util functions."}
midje.parsing.util.zip
+ (:use [utilize.seq :only [first-truthy-fn]])
(:require [clojure.zip :as zip]))
-
+
+
+(defn translate-zipper
+ "Traverses the zipper - for the first predicate that evaluates to truthy for matching a
+ node, calls the corresponding translate function on that node. Then, continues traversing."
+ [form & preds+translate-fns]
+ (loop [loc (zip/seq-zip form)]
+ (if (zip/end? loc)
+ (zip/root loc)
+ (if-let [truthy-fn (first-truthy-fn (take-nth 2 preds+translate-fns) loc)]
+ (recur (zip/next ((get (apply hash-map preds+translate-fns) truthy-fn) loc)))
+ (recur (zip/next loc))))))
+
(defn skip-to-rightmost-leaf
"When positioned at leftmost position of branch, move to the end form.
In a tree, that's the rightmost leaf."
View
14 src/midje/util/form_utils.clj
@@ -1,8 +1,7 @@
(ns ^{:doc "Utility functions dealing with checking or tranforming forms."}
midje.util.form-utils
(:use midje.clojure.core
- midje.parsing.util.core
- [utilize.seq :only (first-truthy-fn)])
+ midje.parsing.util.core)
(:require [clojure.zip :as zip]))
@@ -110,17 +109,6 @@
(defn map-difference [bigger smaller]
(select-keys bigger (difference (set (keys bigger)) (set (keys smaller)))))
-(defn translate-zipper
- "Traverses the zipper - for the first predicate that evaluates to truthy for matching a
- node, calls the corresponding translate function on that node. Then, continues traversing."
- [form & preds+translate-fns]
- (loop [loc (zip/seq-zip form)]
- (if (zip/end? loc)
- (zip/root loc)
- (if-let [truthy-fn (first-truthy-fn (take-nth 2 preds+translate-fns) loc)]
- (recur (zip/next ((get (apply hash-map preds+translate-fns) truthy-fn) loc)))
- (recur (zip/next loc))))))
-
(defmacro pred-cond
"Checks each predicate against the item, returning the corresponding
result if it finds a match, otherwise returning nil.

0 comments on commit 0be9fa0

Please sign in to comment.