Skip to content

Commit

Permalink
Allow keyword names for productions (CLJS only).
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkofreason committed Dec 18, 2017
1 parent b76e7ab commit 6dd773b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/clojure/clara/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@
(coll? source) (seq source)
:else (throw (IllegalArgumentException. "Unknown source value type passed to defsession"))))

;;; ident functions added to clojure.core in 1.9
(defn ident?
"Return true if x is a symbol or keyword"
[x] (or (keyword? x) (symbol? x)))

(defn qualified-keyword?
"Return true if x is a symbol or keyword with a namespace"
[x] (and (keyword? x) (namespace x) true))

(defn build-rule
[name & body]
(let [doc (if (string? (first body)) (first body) nil)
body (if doc (rest body) body)
properties (if (map? (first body)) (first body) nil)
definition (if properties (rest body) body)
{:keys [lhs rhs]} (dsl/split-lhs-rhs definition)
name (if (qualified-keyword? name) name (str (clojure.core/name (com/cljs-ns)) "/" (clojure.core/name name)))

production (cond-> (dsl/parse-rule* lhs rhs properties {})
name (assoc :name (str (clojure.core/name (com/cljs-ns)) "/" (clojure.core/name name)))
name (assoc :name name)
doc (assoc :doc doc))]
production))

Expand All @@ -71,9 +81,10 @@
(let [doc (if (string? (first body)) (first body) nil)
binding (if doc (second body) (first body))
definition (if doc (drop 2 body) (rest body))
name (if (qualified-keyword? name) name (str (clojure.core/name (com/cljs-ns)) "/" (clojure.core/name name)))

query (cond-> (dsl/parse-query* binding definition {})
name (assoc :name (str (clojure.core/name (com/cljs-ns)) "/" (clojure.core/name name)))
name (assoc :name name)
doc (assoc :doc doc))]
query))

Expand Down

0 comments on commit 6dd773b

Please sign in to comment.