Last active
November 29, 2025 08:18
-
-
Save sogaiu/336df633244c7a9a622d1e9c5fd16c77 to your computer and use it in GitHub Desktop.
zipper modify test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (import ./lib/location :as l) | |
| (import ./lib/jipper :as j) | |
| (comment | |
| (def src | |
| (string "(import ./analyze :as a)\n" | |
| "\n" | |
| "(defn main\n" | |
| " [& args]\n" | |
| ` (print "hi"))`)) | |
| (def zloc | |
| (j/zip-down (l/par src))) | |
| (def cur-zloc | |
| (j/search-from zloc | |
| |(match (j/node $) [:symbol _ name] | |
| (when (= "a" name) | |
| $)))) | |
| (j/node cur-zloc) | |
| # => | |
| [:symbol @{:bc 23 :bl 1 :ec 24 :el 1} "a"] | |
| # first edit | |
| (def edit-1-zloc | |
| (j/replace cur-zloc [:symbol @{} "b"])) | |
| (j/node edit-1-zloc) | |
| # => | |
| [:symbol @{} "b"] | |
| (def cur-2-zloc | |
| (j/search-from edit-1-zloc | |
| |(match (j/node $) [:string _ value] | |
| (when (= `"hi"` value) | |
| $)))) | |
| (j/node cur-2-zloc) | |
| # => | |
| [:string @{:bc 10 :bl 5 :ec 14 :el 5} `"hi"`] | |
| # second edit | |
| (def edit-2-zloc | |
| (j/replace cur-2-zloc [:string @{} `"smile!"`])) | |
| (l/gen (j/root edit-2-zloc)) | |
| # => | |
| (string "(import ./analyze :as b)\n" | |
| "\n" | |
| "(defn main\n" | |
| " [& args]\n" | |
| ` (print "smile!"))`) | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment