Last active
October 16, 2020 04:20
-
-
Save pfeodrippe/b8c6c3a39dc6ad27b1d16253ce64bd99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {:deps | |
| {org.clojure/tools.analyzer.jvm {:mvn/version "1.1.0"} | |
| datascript {:mvn/version "1.0.1"}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns query-with-analyzer | |
| (:require | |
| [clojure.tools.analyzer.jvm :as ana] | |
| [clojure.tools.analyzer.ast.query :as ast.q] | |
| [clojure.tools.analyzer.ast :as ast] | |
| [clojure.tools.analyzer.passes.index-vector-nodes :refer [index-vector-nodes]] | |
| [datascript.core :as d])) | |
| (defn q | |
| "From clojure.tools.analyzer.ast.query/q and modified to work with datascript" | |
| [query asts & inputs] | |
| (apply d/q | |
| (ast.q/unfold-expression-clauses query) | |
| (ast.q/db asts) | |
| inputs)) | |
| (->> (q '{:find [?val ?name] | |
| :keys [meta-val def-name] | |
| :where [[?def :op :def] | |
| [?def :name ?name] | |
| [?def :meta ?meta] | |
| [?meta :val ?val]]} | |
| [(ast/prewalk | |
| (ana/analyze '(defn ^:some-meta xx [] "misplaced docstring" 1)) | |
| index-vector-nodes)]) | |
| (filter (comp :some-meta :meta-val)) | |
| (mapv :def-name)) | |
| ;; => [xx] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment