allow declarepath to have parameters, implemented params-reset for enabling recursive parameterized paths
This commit is contained in:
parent
78b16ee5b7
commit
8dd2cb8939
2 changed files with 59 additions and 18 deletions
|
|
@ -129,6 +129,21 @@
|
||||||
params. The return value is an executable selector."}
|
params. The return value is an executable selector."}
|
||||||
bind-params* i/bind-params*)
|
bind-params* i/bind-params*)
|
||||||
|
|
||||||
|
(defn params-reset [params-path]
|
||||||
|
;; TODO: error if not paramsneededpath
|
||||||
|
(let [s (i/params-needed-selector params-path)
|
||||||
|
t (i/params-needed-transformer params-path)]
|
||||||
|
(i/->ParamsNeededPath
|
||||||
|
(i/->TransformFunctions
|
||||||
|
i/RichPathExecutor
|
||||||
|
(fn [params params-idx vals structure next-fn]
|
||||||
|
(s params 0 vals structure next-fn)
|
||||||
|
)
|
||||||
|
(fn [params params-idx vals structure next-fn]
|
||||||
|
(t params 0 vals structure next-fn)
|
||||||
|
))
|
||||||
|
0)))
|
||||||
|
|
||||||
;; Built-in pathing and context operations
|
;; Built-in pathing and context operations
|
||||||
|
|
||||||
(defpath
|
(defpath
|
||||||
|
|
|
||||||
|
|
@ -251,32 +251,58 @@
|
||||||
(defn declared-name [name]
|
(defn declared-name [name]
|
||||||
(symbol (str name "-declared")))
|
(symbol (str name "-declared")))
|
||||||
|
|
||||||
(defmacro declarepath [name]
|
(defn- declarepath* [name num-params]
|
||||||
(let [declared (declared-name name)
|
(let [declared (declared-name name)
|
||||||
rargs [(gensym "params") (gensym "pidx") (gensym "vals")
|
rargs [(gensym "params") (gensym "pidx") (gensym "vals")
|
||||||
(gensym "structure") (gensym "next-fn")]]
|
(gensym "structure") (gensym "next-fn")]]
|
||||||
`(do
|
`(do
|
||||||
(declare ~declared)
|
(declare ~declared)
|
||||||
(def ~name
|
(def ~name
|
||||||
(no-params-compiled-path
|
(if (= ~num-params 0)
|
||||||
(->TransformFunctions
|
(no-params-compiled-path
|
||||||
RichPathExecutor
|
(->TransformFunctions
|
||||||
(fn ~rargs
|
RichPathExecutor
|
||||||
(let [selector# (compiled-selector ~declared)]
|
(fn ~rargs
|
||||||
(selector# ~@rargs)
|
(let [selector# (compiled-selector ~declared)]
|
||||||
))
|
(selector# ~@rargs)
|
||||||
(fn ~rargs
|
))
|
||||||
(let [transformer# (compiled-transformer ~declared)]
|
(fn ~rargs
|
||||||
(transformer# ~@rargs)
|
(let [transformer# (compiled-transformer ~declared)]
|
||||||
))))
|
(transformer# ~@rargs)
|
||||||
))))
|
))))
|
||||||
|
(->ParamsNeededPath
|
||||||
|
(->TransformFunctions
|
||||||
|
RichPathExecutor
|
||||||
|
(fn ~rargs
|
||||||
|
(let [selector# (params-needed-selector ~declared)]
|
||||||
|
(selector# ~@rargs)
|
||||||
|
))
|
||||||
|
(fn ~rargs
|
||||||
|
(let [transformer# (params-needed-transformer ~declared)]
|
||||||
|
(transformer# ~@rargs)
|
||||||
|
)))
|
||||||
|
~num-params
|
||||||
|
)
|
||||||
|
)))))
|
||||||
|
|
||||||
|
|
||||||
|
(defmacro declarepath
|
||||||
|
([name] (declarepath* name 0))
|
||||||
|
([name params]
|
||||||
|
(declarepath* name (count params))))
|
||||||
|
|
||||||
(defmacro providepath [name apath]
|
(defmacro providepath [name apath]
|
||||||
`(def ~(declared-name name)
|
`(let [comped# (comp-paths* ~apath)
|
||||||
(update-in (comp-paths* ~apath)
|
expected-params# (num-needed-params ~name)
|
||||||
[:transform-fns]
|
needed-params# (num-needed-params comped#)]
|
||||||
coerce-tfns-rich)
|
(if-not (= needed-params# expected-params#)
|
||||||
))
|
(throw-illegal "Invalid number of params in provided path, expected "
|
||||||
|
expected-params# " but got " needed-params#))
|
||||||
|
(def ~(declared-name name)
|
||||||
|
(update-in comped#
|
||||||
|
[:transform-fns]
|
||||||
|
coerce-tfns-rich)
|
||||||
|
)))
|
||||||
|
|
||||||
(defmacro extend-protocolpath [protpath & extensions]
|
(defmacro extend-protocolpath [protpath & extensions]
|
||||||
`(extend-protocolpath* ~protpath ~(protpath-sym protpath) ~(vec extensions)))
|
`(extend-protocolpath* ~protpath ~(protpath-sym protpath) ~(vec extensions)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue