GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
e.g. ::foo always is always read as :user/foo, even if it is within the scope of another namespace.
This is related to gh-14 insofar as reading these keywords as expected requires support of the runtime; however, unlike that issue, we shouldn't need to load any code to obtain correct results. We just need to know when in the load process *ns* would change. I've been experimenting with this reworking of kibit.check/read-file with good results:
"Generate a lazy sequence of top level forms from a
(let [ns (atom *ns*)
do-read (fn do-read 
(let [form (binding [*ns* @ns]
(read r false eof))
[ns? new-ns k] (when (sequential? form) form)]
(when (and (symbol? new-ns)
(or (= ns? 'ns) (= ns? 'in-ns)))
(reset! ns (create-ns new-ns)))
(when-not (= form eof)
(cons form (do-read))))))]
This works for the check-reader and check-file cases when an ns form is present, but will fail on check-expr unless the expression in question is from 'user. To be complete, all three should probably accept a new :ns option to specify what the initial reading namespace should be.
I was previously on the verge to do code-loading but that would probably not be a good fit for cljx (or clojurescript, if I ever get time to do kibit for cljs).
AFAIK your approach shouldn't impact the kibit plugin at all so if this version of read-file is useful for cljx then I'll happily accept a pull request.
Yeah, loading code would probably lead to all sorts of nasties.
There are only a couple of forms that are relevant to this and gh-14, and we should be able to statically maintain *ns* and an accurate map of aliases, modulo e.g. macros that emit in-ns, non-top-level ns or require forms, etc.
I'm in the process of attempting to drag a Clojure codebase into being ClojureScript-portable via cljx, so I'll see what I can put together w.r.t. a more complete approach along the way, suitable for a PR.
"statically" maintain *ns* to yield proper namespacing of ::keywords …
Merge pull request #73 from cemerick/master
"statically" maintain *ns* to yield proper namespacing of ::keywords, fixes gh-72