Hi, is anybody here?
I wonder how would i go about search a clj* file for a given keyword with joker
Any pointers?
not sure I understand the question. Can you elaborate?
I want to write a script where i would look for certain keywords in a relatively big project
I was thinking joker would be ideal for the task but cant really figure out how to "read" my clj/s/c source with joker
So i can walk the data to find keywords
Hope this makes sense
if you just need to find keywords, cannot you just use grep? Or do you need to understand semantics of the code (function names vs keywords vs let bindings etc)?
Yup that would be preferred
Also comments etc
it's a bit tricky since read
and read-string
only read one form
but can be done with something like this:
(defn try-read
[]
(try (read)
(catch Error e
::end)))
(loop [f (try-read)]
(if (= ::end f)
(println "done!")
(do
(pprint f)
(recur (try-read)))))
and then running this script like joker read.joke < your-file.clj
note however that read
will skip comments and autoexpand reader macros
for example, (map #(+ %1 %2) [1 2])
will be read as (map (fn [p__148# p__149#] (+ p__148# p__149#)) [1 2])
also, read
doesn't parse the code, so you won't get an AST, just a soup of data structures representing the code
there is also undocumented parse__
function that does return AST, but it's half baked at best
(pprint (parse__ '(map #(+ %1 %2) [1 2])))
would print
{:type :call,
:name "core/map",
:callable {:type :var-ref,
:var #'joker.core/map},
:args [{:type :fn,
:arities [{:type :arity,
:args [p__148#
p__149#],
:body [{:type :call,
:name "core/+",
:callable {:type :var-ref,
:var #'joker.core/+},
:args [{:type :binding,
:name p__148#}
{:type :binding,
:name p__149#}]}]}]}
{:type :vector,
:vector [{:type :literal,
:object 1}
{:type :literal,
:object 2}]}]}
Interesting. Will play with this tmrw. Thanks fornyour help!