Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on assert for syntax quoted elements during slurp or barf operations #317

Open
openvest opened this issue Sep 14, 2024 · 1 comment

Comments

@openvest
Copy link

Version
version 1.1.48

Symptom
Cannot slurp or barf, forward or backward in a syntax quoted element
| indicating the cursor, see:

[:left '[foo| bar]  :right]

Related is trying to slurp forward from:

@(def | x) 42

Actual behavior
assertion error is thrown

Diagnosis
assertion error is inside QuoteNode creation

Action
I know that there has been discussion in a separate thread about asserts; but here it looks to be harmful to the cause.

BTW: Thanks for the great library. It is adding paredit functionality to repl-balance (an update of rebel-readine)

@lread
Copy link
Collaborator

lread commented Sep 14, 2024

Thanks for the issue @openvest, I'm happy to see that folks are starting to use the paredit API more.

Here's my repro of your issue:

(require '[rewrite-clj.paredit :as par]
         '[rewrite-clj.zip :as z])

;; navigate to foo and slurp forward
(def zloc (-> "[:left '[foo bar] :right]"
              z/of-string
              z/down
              z/right
              z/down
              z/down))

(z/string zloc)
;; => "foo"

(par/slurp-forward zloc)
;; => Execution error (AssertionError) at rewrite-clj.node.protocols/assert-sexpr-count (protocols.cljc:177).
;;    Assert failed: can only contain 1 non-whitespace form.
;;    (= (count (without-whitespace nodes)) c)

Very good, I can reproduce!

Let's retry without a quoted node to see what happens:

;; repeat with non-quoted
;; navigate to foo
(def zloc (-> "[:left [foo bar] :right]"
              z/of-string
              z/down
              z/right
              z/down))

(z/string zloc)
;; => "foo"

(-> zloc 
    par/slurp-forward
    z/root-string)
;; => "[:left [foo bar :right]]"

Good, no probs without quoted node.

I had launched into reviewing the paredit API with various fixes, but got distracted by other projects. This one is new to me, so thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants