after a bit of back and forth, it appears that the following idea leads to automatic closing of delimiters:
(defmethod parse-next* :eof
[reader]
(when-let [[open close row col] *delimiter*]
nil
#_(let [opening {:row row
:col col
:message (format "Found an opening %s with no matching %s" open close)}
closing (assoc (reader/position reader :row :col)
:message (format "Expected a %s to match %s from line %d" close open row))]
(throw (ex-info "Syntax error"
{:findings [opening closing]})))))
this is in clj-kondo's vendored rewrite-clj, fwiw. it's ofc a sketch -- need to arrange for the behavior to be optional i guess.@lee at some point may be we can go over some or all of Marc O'Morain's PR 527 to clj-kondo -- https://github.com/borkdude/clj-kondo/pull/527 -- i'm particularly interested in: > Change rewrite-clj.parser.core/delimiters to keep track of a tuple of [open, close, row, col] rather than just the expected closing delimiter. The extra three fields allow is to construct more informative error messages when a parse error occurs.
looks interesting @sogaiu!
regarding detecting expressions, i realized that it is insufficient to send the text up through the current cursor position (this may not handle the case of when the cursor is in the middle of an identifier) -- possibly a work-around is to send up to the end of the line / row that the current cursor is on.
@sogaiu can you give an example of a complete input and the part you want to send to the REPL?
@borkdude here is an example: complete editor buffer content
(comment
(-> (rz/of-string "(+ 1 1)")
rz/down
rz/tag) ; request detection of expression between the 'a' and 'g' on this line
rz/right
rz/string)
)
the original idea was to send just:
(comment
(-> (rz/of-string "(+ 1 1)")
rz/down
rz/ta
but this will fail to identify rz/tag
because the 'g' is missing.
instead, sending up through the end of the line with rz/ta
on it:
(comment
(-> (rz/of-string "(+ 1 1)")
rz/down
rz/tag)
seems like it could work.i made an attempt to get this to work with rewrite-cljs-playground -- here's what i've got so far: https://github.com/sogaiu/rewrite-cljs-playground/commit/7074cfc222aa65c93020bddeed83c0236e4f86b8
so short i wonder if i'm missing some important things...