this is a vote in favor of some consideration of this issue: https://github.com/lread/rewrite-cljs-playground/blob/master/todos.org#consider-allowing-metadata-to-be-a-child
am trying to get at the name for an ns form, and atm, i'm doing something like this:
(defn ns?
[zloc]
(when (rz/list? zloc)
(when-let [head (rz/down zloc)]
(let [tag (rz/tag head)
find-ns-name (fn [start-zloc]
(let [rzloc (rz/right start-zloc)
r-tag (rz/tag rzloc)]
(cond (= r-tag :token)
rzloc
;;
(= r-tag :meta)
(-> rzloc
rz/down
rz/right)
;;
:else
nil)))]
(cond (= tag :token)
(when (= (rz/string head) "ns")
(find-ns-name head))
;;
(= tag :meta)
(let [target (-> head
rz/down
rz/right)]
(when (= (rz/string target) "ns")
(find-ns-name head)))
;;
:else
nil)))))
the metadata being the container for things seems to make taversal awkward
I've moved this to an issue https://github.com/lread/rewrite-cljs-playground/issues/2
borkdude was talking with dominicm briefly about partial parsing for edamame -- does that sound like something that's remotely doable in rewrite-clj* at some point?
thanks, I will capture this is my notes!
I donβt know @sogaiu, I have not thought about that yet
thanks -- just putting something out for consideration π i was hoping that may be there's a chance someone else has figured out how to deal with not well-formed stuff...
@lee saw the nice logo for the first time :thumbsup:
does it seem possible / practical for there to be a mode of operation where, when rewrite-clj* encounters a situation where it is expecting a closing delimiter but doesn't find one to fake one being there? possibly then subsequently ignoring anything else it was asked to read, then try to close as many delimiters as necessary to complete parsing? in a slightly more general formulation: upon encountering some classes of errors (e.g. missing delimiter), is it possible / practical to just try to make sense of whatever has been encountered so far while ignoring everything else that would follow?
@sogaiu I think that is technically possible. Clj-kondo has a fork of tools.reader which warns about which opening paren was expected to close, e.g. [)
, so it could have just pretended to read []
instead
but instead of that it throws an error with a better error message than tools.reader currently throws
$ clj-kondo --lint - <<< '[)'
<stdin>:1:1: error: Mismatched bracket: found an opening [ and a closing ) on line 1
<stdin>:1:2: error: Mismatched bracket: found an opening [ on line 1 and a closing )
linting took 23ms, errors: 2, warnings: 0
as you can see, it also spits out two errors, so you get squiggles in two places
What is your use case for this?
@borkdude i am writing an external tool that among other things tries to "detect the expression before cursor / point". suppose i initially write this code in an editor buffer:
(comment
(-> (rz/of-string "(+ 1 1)")
rz/down
rz/right
rz/string)
...
)
at some point i want to take a look at something a bit different:
(comment
(-> (rz/of-string "(+ 1 1)")
rz/down
rz/tag) ; request detection of expression here so it can be sent to repl
rz/right
rz/string)
...
)
i'd like to be able to send the text from the beginning of the file up through "rz/tag)" to detect:
(-> (rz/of-string "(+ 1 1)")
rz/down
rz/tag)
right now all of the text of the buffer is sent and it is not successfully read/parsed.good luck. sleep time
thanks π