code.query.match
compile-matcher
added in 3.0
(compile-matcher template)creates a matcher given a datastructure declaring the actual template
((compile-matcher {:is ’hello}) (nav/parse-string “hello”)) => true
matcher?
added in 3.0
(matcher? x)checks if element is a matcher
(matcher? (matcher string?)) => true
p-ancestor
added in 3.0
(p-ancestor template)checks that any parent container matches ((p-ancestor {:form ’if}) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next)) => true ((p-ancestor ’if) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next)) => true
p-and
added in 3.0
(p-and & matchers)takes multiple predicates and ensures that all are correct ((p-and (p-code #“defn”) (p-type :token)) (nav/parse-string “(defn ^{:a 1} x [])”)) => false
((p-and (p-code #“defn”) (p-type :list)) (nav/parse-string “(defn ^{:a 1} x [])”)) => true
p-child
added in 3.0
(p-child template)checks that there is a child of a container that has a certain characteristic ((p-child {:form ’=}) (nav/parse-string “(if (= x y))”)) => true
((p-child ’=) (nav/parse-string “(if (= x y))”)) => false
p-code
added in 3.0
(p-code template)checks if the form matches a string in the form of a regex expression ((p-code #“defn”) (nav/parse-string “(defn ^{:a 1} x [])”)) => true
p-contains
added in 3.0
(p-contains template)checks that any element (deeply nested also) of the container matches ((p-contains ’=) (nav/parse-string “(if (= x y))”)) => true
((p-contains ’x) (nav/parse-string “(if (= x y))”)) => true
p-equal
added in 3.0
(p-equal template)checks if the node is equivalent, takes meta into account ((p-equal ’^{:a 1} defn) (nav/parse-string “defn”)) => false
((p-equal ’^{:a 1} defn) (nav/parse-string “^{:a 1} defn”)) => true
((p-equal ’^{:a 1} defn) (nav/parse-string “^{:a 2} defn”)) => false
p-equal-loop
added in 3.0
(p-equal-loop expr template)p-first
added in 3.0
(p-first template)p-fn
added in 3.0
(p-fn template)takes a predicate function to check the state of the zipper ((p-fn (fn nav (-> nav (nav/tag) (= :symbol)))) (nav/parse-string “defn”)) => true
p-form
added in 3.0
(p-form template)checks if it is a form with the symbol as the first element ((p-form ’defn) (nav/parse-string “(defn x [])”)) => true ((p-form ’let) (nav/parse-string “(let [])”)) => true
p-is
added in 3.0
(p-is template)checks if node is equivalent, does not meta into account ((p-is ’defn) (nav/parse-string “defn”)) => true
((p-is ’^{:a 1} defn) (nav/parse-string “defn”)) => true
((p-is ’defn) (nav/parse-string “is”)) => false
((p-is ’(defn & _)) (nav/parse-string “(defn x [])”)) => false
p-last
added in 3.0
(p-last template)p-left
added in 3.0
(p-left template)checks that the element on the left has a certain characteristic ((p-left ’=) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next nav/next)) => true
((p-left ’if) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next)) => true
p-left-most
added in 3.0
(p-left-most bool)checks that any element on the right has a certain characteristic ((p-left-most true) (-> (nav/parse-string “(= x y)”) nav/down)) => true
((p-left-most true) (-> (nav/parse-string “(= x y)”) nav/down nav/next)) => false
p-left-of
added in 3.0
(p-left-of template)checks that any element on the left has a certain characteristic ((p-left-of ’=) (-> (nav/parse-string “(= x y)”) nav/down nav/next)) => true
((p-left-of ’=) (-> (nav/parse-string “(= x y)”) nav/down nav/next nav/next)) => true
p-meta
added in 3.0
(p-meta template)checks if meta is the same ((p-meta {:a 1}) (nav/down (nav/parse-string “^{:a 1} defn”))) => true
((p-meta {:a 1}) (nav/down (nav/parse-string “^{:a 2} defn”))) => false
p-not
added in 3.0
(p-not matcher)checks if node is the inverse of the given matcher
((p-not (p-is ’if)) (nav/parse-string “defn”)) => true
((p-not (p-is ’if)) (nav/parse-string “if”)) => false
p-nth
added in 3.0
(p-nth [num template])p-nth-ancestor
added in 3.0
(p-nth-ancestor [num template])search for match n-levels up
((p-nth-ancestor 2 {:contains 3}) (-> (nav/parse-string “(* (- (+ 1 2) 3) 4)”) nav/down nav/right nav/down nav/right nav/down)) => true
p-nth-contains
added in 3.0
(p-nth-contains [num template])search for match n-levels down
((p-nth-contains 2 {:contains 1}) (nav/parse-string “(* (- (+ 1 2) 3) 4)”)) => true
p-nth-left
added in 3.0
(p-nth-left [num template])checks that the last element of the container has a certain characteristic ((p-nth-left 0 ’defn) (-> (nav/parse-string “(defn [] 1)”) nav/down)) => true
((p-nth-left 1 ^:& vector?) (-> (nav/parse-string “(defn [] 1)”) nav/down nav/right-most)) => true
p-nth-right
added in 3.0
(p-nth-right [num template])p-or
added in 3.0
(p-or & matchers)takes multiple predicates and ensures that at least one is correct ((p-or (p-code #“defn”) (p-type :token)) (nav/parse-string “(defn ^{:a 1} x [])”)) => true
((p-or (p-code #“defn”) (p-type :list)) (nav/parse-string “(defn ^{:a 1} x [])”)) => true
p-parent
added in 3.0
(p-parent template)checks that the parent of the element contains a certain characteristic ((p-parent ’defn) (-> (nav/parse-string “(defn x [])”) nav/next nav/next)) => true
((p-parent {:parent ’if}) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next)) => true
((p-parent {:parent ’if}) (-> (nav/parse-string “(if (= x y))”) nav/down)) => false
p-pattern
added in 3.0
(p-pattern template)checks if the form matches a particular pattern ((p-pattern ’(defn ^:% symbol? & _)) (nav/parse-string “(defn ^{:a 1} x [])”)) => true
((p-pattern ’(defn ^:% symbol? ^{:% true :? true} string? [])) (nav/parse-string “(defn ^{:a 1} x [])”)) => true
p-right
added in 3.0
(p-right template)checks that the element on the right has a certain characteristic ((p-right ’x) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next)) => true
((p-right {:form ’=}) (-> (nav/parse-string “(if (= x y))”) nav/down)) => true
p-right-most
added in 3.0
(p-right-most bool)checks that any element on the right has a certain characteristic ((p-right-most true) (-> (nav/parse-string “(= x y)”) nav/down nav/next)) => false
((p-right-most true) (-> (nav/parse-string “(= x y)”) nav/down nav/next nav/next)) => true
p-right-of
added in 3.0
(p-right-of template)checks that any element on the right has a certain characteristic ((p-right-of ’x) (-> (nav/parse-string “(= x y)”) nav/down)) => true
((p-right-of ’y) (-> (nav/parse-string “(= x y)”) nav/down)) => true
((p-right-of ’z) (-> (nav/parse-string “(= x y)”) nav/down)) => false
p-sibling
added in 3.0
(p-sibling template)checks that any element on the same level has a certain characteristic ((p-sibling ’=) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next)) => false
((p-sibling ’x) (-> (nav/parse-string “(if (= x y))”) nav/down nav/next nav/next)) => true
p-type
added in 3.0
(p-type template)check on the type of element ((p-type :symbol) (nav/parse-string “defn”)) => true
((p-type :symbol) (-> (nav/parse-string “^{:a 1} defn”) nav/down nav/right)) => true
tree-depth-search
added in 3.0
(tree-depth-search nav m-fn level dir1 dir2)helper function for p-nth-contains