allow declarepath to have parameters, implemented params-reset for enabling recursive parameterized paths

This commit is contained in:
Nathan Marz 2016-01-30 12:03:46 -08:00
parent 78b16ee5b7
commit 8dd2cb8939
2 changed files with 59 additions and 18 deletions

View file

@ -129,6 +129,21 @@
params. The return value is an executable selector."}
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
(defpath

View file

@ -251,13 +251,14 @@
(defn declared-name [name]
(symbol (str name "-declared")))
(defmacro declarepath [name]
(defn- declarepath* [name num-params]
(let [declared (declared-name name)
rargs [(gensym "params") (gensym "pidx") (gensym "vals")
(gensym "structure") (gensym "next-fn")]]
`(do
(declare ~declared)
(def ~name
(if (= ~num-params 0)
(no-params-compiled-path
(->TransformFunctions
RichPathExecutor
@ -269,14 +270,39 @@
(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]
`(def ~(declared-name name)
(update-in (comp-paths* ~apath)
`(let [comped# (comp-paths* ~apath)
expected-params# (num-needed-params ~name)
needed-params# (num-needed-params comped#)]
(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]
`(extend-protocolpath* ~protpath ~(protpath-sym protpath) ~(vec extensions)))