implement pathed collectors and convert collect and collect-one
This commit is contained in:
parent
bcfcd02f80
commit
fc6392cc9e
2 changed files with 45 additions and 25 deletions
|
|
@ -137,6 +137,7 @@
|
||||||
latefns-sym (gensym "latefns")
|
latefns-sym (gensym "latefns")
|
||||||
latefn-syms (vec (i/gensyms (count paths)))]
|
latefn-syms (vec (i/gensyms (count paths)))]
|
||||||
(i/pathed-path*
|
(i/pathed-path*
|
||||||
|
i/paramspath*
|
||||||
paths
|
paths
|
||||||
latefns-sym
|
latefns-sym
|
||||||
[latefn-syms latefns-sym]
|
[latefn-syms latefns-sym]
|
||||||
|
|
@ -146,6 +147,7 @@
|
||||||
(defmacro variable-pathed-path [[latepaths-seq-sym paths-seq] & impls]
|
(defmacro variable-pathed-path [[latepaths-seq-sym paths-seq] & impls]
|
||||||
(let [latefns-sym (gensym "latefns")]
|
(let [latefns-sym (gensym "latefns")]
|
||||||
(i/pathed-path*
|
(i/pathed-path*
|
||||||
|
i/paramspath*
|
||||||
paths-seq
|
paths-seq
|
||||||
latefns-sym
|
latefns-sym
|
||||||
[]
|
[]
|
||||||
|
|
@ -154,6 +156,19 @@
|
||||||
impls
|
impls
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
(defmacro pathed-collector [[name path] impl]
|
||||||
|
(let [latefns-sym (gensym "latefns")
|
||||||
|
latefn (gensym "latefn")]
|
||||||
|
(i/pathed-path*
|
||||||
|
i/paramscollector*
|
||||||
|
[path]
|
||||||
|
latefns-sym
|
||||||
|
[[latefn] latefns-sym]
|
||||||
|
[name `(~latefn ~i/PARAMS-SYM ~i/PARAMS-IDX-SYM)]
|
||||||
|
impl
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
;; Built-in pathing and context operations
|
;; Built-in pathing and context operations
|
||||||
|
|
||||||
(def ALL (i/->AllStructurePath))
|
(def ALL (i/->AllStructurePath))
|
||||||
|
|
@ -273,11 +288,17 @@
|
||||||
(transform* [aset structure next-fn]
|
(transform* [aset structure next-fn]
|
||||||
(i/filter-transform aset structure next-fn)))
|
(i/filter-transform aset structure next-fn)))
|
||||||
|
|
||||||
(defn collect [& selector]
|
(defn collect [& path]
|
||||||
(i/->SelectCollector select (i/comp-paths* selector)))
|
(pathed-collector [late path]
|
||||||
|
(collect* [this structure]
|
||||||
|
(compiled-select late structure)
|
||||||
|
)))
|
||||||
|
|
||||||
(defn collect-one [& selector]
|
(defn collect-one [& path]
|
||||||
(i/->SelectCollector select-one (i/comp-paths* selector)))
|
(pathed-collector [late path]
|
||||||
|
(collect* [this structure]
|
||||||
|
(compiled-select-one late structure)
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
;;TODO: add this comment:
|
;;TODO: add this comment:
|
||||||
|
|
|
||||||
|
|
@ -381,12 +381,30 @@
|
||||||
~num-params
|
~num-params
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
(defn paramscollector* [post-bindings num-params [_ [_ structure-sym] & body]]
|
||||||
|
`(let [collector# (fn [~PARAMS-SYM ~PARAMS-IDX-SYM vals# ~structure-sym next-fn#]
|
||||||
|
(let [~@post-bindings ~@[] ; to avoid syntax highlighting issues
|
||||||
|
c# (do ~@body)]
|
||||||
|
(next-fn#
|
||||||
|
~PARAMS-SYM
|
||||||
|
(+ ~PARAMS-IDX-SYM ~num-params)
|
||||||
|
(conj vals# c#)
|
||||||
|
~structure-sym)
|
||||||
|
))]
|
||||||
|
(->ParamsNeededPath
|
||||||
|
(->TransformFunctions
|
||||||
|
RichPathExecutor
|
||||||
|
collector#
|
||||||
|
collector# )
|
||||||
|
~num-params
|
||||||
|
)))
|
||||||
|
|
||||||
(defn num-needed-params [path]
|
(defn num-needed-params [path]
|
||||||
(if (instance? CompiledPath path)
|
(if (instance? CompiledPath path)
|
||||||
0
|
0
|
||||||
(:num-needed-params path)))
|
(:num-needed-params path)))
|
||||||
|
|
||||||
(defn pathed-path* [paths-seq latefns-sym pre-bindings post-bindings impls]
|
(defn pathed-path* [builder paths-seq latefns-sym pre-bindings post-bindings impls]
|
||||||
(let [num-params-sym (gensym "num-params")]
|
(let [num-params-sym (gensym "num-params")]
|
||||||
`(let [paths# (map comp-paths* ~paths-seq)
|
`(let [paths# (map comp-paths* ~paths-seq)
|
||||||
needed-params# (map num-needed-params paths#)
|
needed-params# (map num-needed-params paths#)
|
||||||
|
|
@ -403,32 +421,13 @@
|
||||||
offsets#
|
offsets#
|
||||||
paths#)
|
paths#)
|
||||||
~@pre-bindings
|
~@pre-bindings
|
||||||
ret# ~(paramspath* post-bindings num-params-sym impls)
|
ret# ~(builder post-bindings num-params-sym impls)
|
||||||
]
|
]
|
||||||
(if (= 0 ~num-params-sym)
|
(if (= 0 ~num-params-sym)
|
||||||
(bind-params* ret# nil 0)
|
(bind-params* ret# nil 0)
|
||||||
ret#
|
ret#
|
||||||
))))
|
))))
|
||||||
|
|
||||||
|
|
||||||
(defn paramscollector* [bindings num-params [_ [_ structure-sym] & body]]
|
|
||||||
`(let [collector# (fn [~PARAMS-SYM ~PARAMS-IDX-SYM vals# ~structure-sym next-fn#]
|
|
||||||
(let [~@bindings ~@[] ; to avoid syntax highlighting issues
|
|
||||||
c# (do ~@body)]
|
|
||||||
(next-fn#
|
|
||||||
~PARAMS-SYM
|
|
||||||
(+ ~PARAMS-IDX-SYM ~num-params)
|
|
||||||
(conj vals# c#)
|
|
||||||
~structure-sym)
|
|
||||||
))]
|
|
||||||
(->ParamsNeededPath
|
|
||||||
(->TransformFunctions
|
|
||||||
RichPathExecutor
|
|
||||||
collector#
|
|
||||||
collector# )
|
|
||||||
~num-params
|
|
||||||
)))
|
|
||||||
|
|
||||||
(defn make-param-retrievers [params]
|
(defn make-param-retrievers [params]
|
||||||
(->> params
|
(->> params
|
||||||
(map-indexed
|
(map-indexed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue