Evaluate ('e') with bracket in string
tom-adsfund opened this issue · 4 comments
This is a good example of why maybe you should use a parser in general!
In the following example if I press 'e' at -> it fails to evaluate the expression because of the bracket in the string.
(require '(clojure [zip :as zip]))
(->
(nth (iterate zip/next (zip/vector-zip (core/parser "(1 2 3)"))) 8)
(zip/replace "#(")
zip/root
)
Strange issue. Close it?!
Maybe. When evaluating s-expression at point, the paren matching to figure out the s-expression to evaluate, does not take into account, if a string contains unmatched parenthesis. A much simpler example is
(str "(" "abc")
If the cursor is on "str" and eval-sexp-at-point is called, it will fail, because the paren in the string is not ignored, which it should be, if everything was perfekt. It will seem like the paren to the left has not matching paren, although it has.
@mogenslund I recently learned about tree-sitter, an "efficient incremental parser" compiler which has a Clojure parser (https://github.com/sogaiu/tree-sitter-clojure). It might be worth somehow converting the linked public domain parser from the generated C to Clojure, which would then allow powerful structural editing as we envisioned long ago now!
Just saw this: https://github.com/nextjournal/lezer-clojure
It's a Clojure parser for the Lezer parser system that produces a Javascript program to parse the code. More naturally compatible with Java.