add docstrings to zippers

This commit is contained in:
Nathan Marz 2016-04-25 17:47:10 -04:00
parent 48ad46d5e5
commit f5c5284ae1
2 changed files with 34 additions and 10 deletions

View file

@ -20,7 +20,9 @@
(def XML-ZIP (zipper zip/xml-zip)) (def XML-ZIP (zipper zip/xml-zip))
(def NEXT (def ^{:doc "Navigate to the next element in the structure.
If no next element, works like STOP."}
NEXT
(s/comp-paths (s/comp-paths
(s/view zip/next) (s/view zip/next)
(s/if-path zip/end? (s/if-path zip/end?
@ -44,11 +46,20 @@
;; like they are for maps/graphs. The path following RIGHT could ;; like they are for maps/graphs. The path following RIGHT could
;; insert lots of elements all over the sequence, and there's no ;; insert lots of elements all over the sequence, and there's no
;; way to determine how to get "back". ;; way to determine how to get "back".
(def RIGHT (mk-zip-nav zip/right)) (def ^{:doc "Navigate to the element to the right.
(def LEFT (mk-zip-nav zip/left)) If no element there, works like STOP."}
RIGHT (mk-zip-nav zip/right))
(def ^{:doc "Navigate to the element to the left.
If no element there, works like STOP."}
LEFT (mk-zip-nav zip/left))
(def DOWN (mk-zip-nav zip/down)) (def DOWN (mk-zip-nav zip/down))
(def UP (mk-zip-nav zip/up)) (def UP (mk-zip-nav zip/up))
(def PREV (mk-zip-nav zip/prev))
(def ^{:doc "Navigate to the previous element.
If this is the first element, works like STOP."}
PREV (mk-zip-nav zip/prev))
(def RIGHTMOST (s/view zip/rightmost)) (def RIGHTMOST (s/view zip/rightmost))
(def LEFTMOST (s/view zip/leftmost)) (def LEFTMOST (s/view zip/leftmost))
@ -65,14 +76,18 @@
inserts) inserts)
)) ))
(defpath INNER-RIGHT [] (defpath ^{:doc "Navigate to the empty subsequence directly to the
right of this element."}
INNER-RIGHT []
(select* [this structure next-fn] (select* [this structure next-fn]
(next-fn [])) (next-fn []))
(transform* [this structure next-fn] (transform* [this structure next-fn]
(inner-insert structure next-fn zip/insert-right zip/right zip/left) (inner-insert structure next-fn zip/insert-right zip/right zip/left)
)) ))
(defpath INNER-LEFT [] (defpath ^{:doc "Navigate to the empty subsequence directly to the
left of this element."}
INNER-LEFT []
(select* [this structure next-fn] (select* [this structure next-fn]
(next-fn [])) (next-fn []))
(transform* [this structure next-fn] (transform* [this structure next-fn]
@ -87,7 +102,11 @@
(zip/edit structure next-fn) (zip/edit structure next-fn)
)) ))
(defpath NODE-SEQ [] (defpath ^{:doc "Navigate to the subsequence containing only
the node currently pointed to. This works just
like srange and can be used to remove elements
from the structure"}
NODE-SEQ []
(select* [this structure next-fn] (select* [this structure next-fn]
(next-fn [(zip/node structure)]) (next-fn [(zip/node structure)])
) )
@ -97,7 +116,10 @@
(zip/remove inserted) (zip/remove inserted)
))) )))
(declarepath find-first [predfn]) (declarepath ^{:doc "Navigate the zipper to the first element
in the structure matching predfn. A linear scan
is done using NEXT to find the element."}
find-first [predfn])
(providepath find-first (providepath find-first
(s/if-path [NODE s/pred] (s/if-path [NODE s/pred]
@ -105,7 +127,9 @@
[NEXT (s/params-reset find-first)] [NEXT (s/params-reset find-first)]
)) ))
(declarepath NEXT-WALK) (declarepath ^{:doc "Navigate to every element reachable using calls
to NEXT"}
NEXT-WALK)
(providepath NEXT-WALK (providepath NEXT-WALK
(s/stay-then-continue (s/stay-then-continue