rewrite-clj

https://github.com/clj-commons/rewrite-clj
2019-11-12T00:11:15.175400Z

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

2019-11-12T00:12:16.176400Z

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)))))

2019-11-12T00:13:36.177100Z

the metadata being the container for things seems to make taversal awkward

πŸ‘ 1
lread 2019-11-15T23:08:01.236100Z

I've moved this to an issue https://github.com/lread/rewrite-cljs-playground/issues/2

2019-11-12T02:43:07.178600Z

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?

lread 2019-11-12T03:04:06.179300Z

thanks, I will capture this is my notes!

lread 2019-11-12T03:09:39.180500Z

I don’t know @sogaiu, I have not thought about that yet

2019-11-12T03:44:14.181600Z

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...

2019-11-12T04:59:24.182Z

@lee saw the nice logo for the first time :thumbsup:

2019-11-12T22:56:50.186700Z

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?

borkdude 2019-11-12T23:05:42.188100Z

@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

borkdude 2019-11-12T23:06:12.188600Z

but instead of that it throws an error with a better error message than tools.reader currently throws

borkdude 2019-11-12T23:06:39.188900Z

$ 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

borkdude 2019-11-12T23:07:29.189500Z

as you can see, it also spits out two errors, so you get squiggles in two places

borkdude 2019-11-12T23:09:09.190400Z

What is your use case for this?

2019-11-12T23:16:33.195600Z

@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.

borkdude 2019-11-12T23:18:35.196100Z

good luck. sleep time

2019-11-12T23:18:44.196400Z

thanks πŸ™‚