Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Add bindings for match context
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereOverfl0w committed May 27, 2017
1 parent 3805280 commit c25db87
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/mach/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,25 @@
[expr target]
(postwalk (fn [x] (or (and (symbol? x) (get target x)) x)) expr))

(def ^:dynamic *target-ctx* nil)
(def ^:dynamic *matcher-ctx* nil)

(defn- with-target-ctx-bindings
[expr target]
(list 'binding (into [] cat (-> target
(select-keys [:mach/_target-ctx :mach/_matcher-ctx])
(rename-keys {:mach/_target-ctx 'mach.core/*target-ctx*
:mach/_matcher-ctx 'mach.core/*matcher-ctx*})))
expr))

(defn- eval-rule
"Evals Mach rule and returns the result if successful, throws an
error if not."
[code target machfile]
(let [code (-> code
(resolve-symbols target)
(with-prop-bindings machfile))]
(with-prop-bindings machfile)
(with-target-ctx-bindings target))]
;; Eval the code
(let [{:keys [value error]} (cljs/eval repl/st code identity)]
(when error
Expand Down

0 comments on commit c25db87

Please sign in to comment.