($ context path & args)select and manipulation of clojure source code
($ {:string "(defn hello1) (defn hello2)"} [(defn _ ^:%+ (keyword "oeuoeuoe"))]) => '[(defn hello1 :oeuoeuoe) (defn hello2 :oeuoeuoe)]
($ {:string "(defn hello1) (defn hello2)"} [(defn _ | ^:%+ (keyword "oeuoeuoe"))]) => '[:oeuoeuoe :oeuoeuoe]
(->> ($ {:string "(defn hello1) (defn hello2)"} [(defn _ | ^:%+ (keyword "oeuoeuoe"))] {:return :string})) => [":oeuoeuoe" ":oeuoeuoe"]
($ (nav/parse-root "a b c") [{:is a}]) => '[a]
select and manipulation of clojure source code
($ {:string "(defn hello1) (defn hello2)"}
[(defn _ ^:%+ (keyword "oeuoeuoe"))])
=> '[(defn hello1 :oeuoeuoe) (defn hello2 :oeuoeuoe)]
($ {:string "(defn hello1) (defn hello2)"}
[(defn _ | ^:%+ (keyword "oeuoeuoe"))])
=> '[:oeuoeuoe :oeuoeuoe]
(->> ($ {:string "(defn hello1) (defn hello2)"}
[(defn _ | ^:%+ (keyword "oeuoeuoe"))]
{:return :string}))
=> [":oeuoeuoe" ":oeuoeuoe"]
($ (nav/parse-root "a b c") [{:is a}])
=> '[a](context-zloc context)gets the context for loading forms
gets the context for loading forms
(match zloc selector)matches the source code (match (nav/parse-string "(+ 1 1)") '(symbol? _ _)) => false
(match (nav/parse-string "(+ 1 1)") '(^:% symbol? _ _)) => true
(match (nav/parse-string "(+ 1 1)") '(^:%- symbol? _ | _)) => true
(match (nav/parse-string "(+ 1 1)") '(^:%+ symbol? _ _)) => false
matches the source code (match (nav/parse-string "(+ 1 1)") '(symbol? _ _)) => false (match (nav/parse-string "(+ 1 1)") '(^:% symbol? _ _)) => true (match (nav/parse-string "(+ 1 1)") '(^:%- symbol? _ | _)) => true (match (nav/parse-string "(+ 1 1)") '(^:%+ symbol? _ _)) => false
(modify zloc selectors func)(modify zloc selectors func opts)modifies location given a function (nav/string (modify (nav/parse-root "^:a (defn hello3) (defn hello)") ['(defn | _)] (fn [zloc] (nav/insert-left zloc :hello)))) => "^:a (defn :hello hello3) (defn :hello hello)"
modifies location given a function
(nav/string
(modify (nav/parse-root "^:a (defn hello3) (defn hello)") ['(defn | _)]
(fn [zloc]
(nav/insert-left zloc :hello))))
=> "^:a (defn :hello hello3) (defn :hello hello)"(select zloc selectors)(select zloc selectors opts)selects all patterns from a starting point (map nav/value (select (nav/parse-root "(defn hello [] (if (try))) (defn hello2 [] (if (try)))") '[defn if try])) => '((defn hello [] (if (try))) (defn hello2 [] (if (try))))
selects all patterns from a starting point
(map nav/value
(select (nav/parse-root "(defn hello [] (if (try))) (defn hello2 [] (if (try)))")
'[defn if try]))
=> '((defn hello [] (if (try)))
(defn hello2 [] (if (try))))(traverse zloc pattern)(traverse zloc pattern func)uses a pattern to traverse as well as to edit the form
(nav/value (traverse (nav/parse-string "^:a (+ () 2 3)") '(+ () 2 3))) => '(+ () 2 3)
(nav/value (traverse (nav/parse-string "()") '(^:&+ hello))) => '(hello)
(nav/value (traverse (nav/parse-string "()") '(+ 1 2 3))) => (throws)
(nav/value (traverse (nav/parse-string "(defn hello "world" {:a 1} [])") '(defn ^:% symbol? ^:?%- string? ^:?%- map? ^:% vector? & _))) => '(defn hello [])
uses a pattern to traverse as well as to edit the form
(nav/value
(traverse (nav/parse-string "^:a (+ () 2 3)")
'(+ () 2 3)))
=> '(+ () 2 3)
(nav/value
(traverse (nav/parse-string "()")
'(^:&+ hello)))
=> '(hello)
(nav/value
(traverse (nav/parse-string "()")
'(+ 1 2 3)))
=> (throws)
(nav/value
(traverse (nav/parse-string "(defn hello \"world\" {:a 1} [])")
'(defn ^:% symbol? ^:?%- string? ^:?%- map? ^:% vector? & _)))
=> '(defn hello [])(wrap-return f)decides whether to return a string, zipper or sexp representation`
decides whether to return a string, zipper or sexp representation`
(wrap-vec f)helper for dealing with vectors
helper for dealing with vectors
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |