Skip to content

Instantly share code, notes, and snippets.

@frenchy64 frenchy64/taj.clj
Created Feb 15, 2014

What would you like to do?
(ns ^:skip-wiki clojure.core.typed.analyze-clj
(:require [ :as analyze]
[ :as hygienic]
[ :as ta]
[ :as taj]
[ :as tr]
[ :as readers]
[clojure.string :as str]
[ :as io]
[clojure.core.typed.utils :as u]))
(defn ast-for-ns
"Returns a vector of AST nodes contained
in the given namespace symbol nsym"
{:pre [(symbol? nsym)]}
(u/p :analyze/ast-for-ns
;copied basic approach from tools.emitter.jvm
(let [res nsym
p (str (str/replace res #"\." "/") ".clj")
eof (reify)
p (if (.startsWith p "/") (subs p 1) p)
file (-> p io/resource io/reader slurp)
reader (readers/indexing-push-back-reader file)]
(binding [*ns* (or (find-ns nsym)
(loop [asts []]
(let [form (tr/read reader false eof)]
(if (not= eof form)
(recur (conj asts (taj/analyze form (taj/empty-env))))
; (do (ast-for-ns ' nil)
user=> (doc
(quote ([] [reader] [reader eof-error? sentinel] [reader eof-error? sentinel recursive?]))
Reads the first object from an IPushbackReader or a
Returns the object read. If EOF, throws if eof-error? is true.
Otherwise returns sentinel. If no stream is providen, *in* will be used.
Note that read can execute code (controlled by *read-eval*),
and as such should be used only with trusted sources.
To read data structures only, use
Note that the function signature of and is not the same for eof-handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.