Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active November 3, 2025 10:39
Show Gist options
  • Select an option

  • Save sogaiu/59fdb8cefee5941c27fff7d98f7ce354 to your computer and use it in GitHub Desktop.

Select an option

Save sogaiu/59fdb8cefee5941c27fff7d98f7ce354 to your computer and use it in GitHub Desktop.
take 3
(import ./location :as l)
(import ./zipper :as j)
(import ./loc-jipper :as j)
(comment
(def info-jdn-src
```
{:name "jeep"
:version "DEVEL"
:description "A Janet bundle manager"
:author "Michael Camilleri"
:license "MIT"
:url "https://github.com/pyrmont/jeep"
:repo "git+https://github.com/pyrmont/jeep"
:vendored {
"deps" [
{:name "argy-bargy"
:url "https://github.com/pyrmont/argy-bargy"
:prefix "argy-bargy"
:files ["argy-bargy.janet"
"LICENSE"]}]}
}
```)
# parse source
(def tree (l/par info-jdn-src))
# find the target location (the :name keyword in the struct
# in the tuple associated with the string "deps")
(def target-zloc
(-?> tree
# creates zipper and navigates "down" into it
j/zip-down
# search from current location for the string "deps"
# note that the current location is updated
(j/search-from |(match (j/node $)
[:string _ `"deps"`]
$))
# search from the current location for the keyword :name
(j/search-from |(match (j/node $)
[:keyword _ ":name"]
$))))
# add `:tag "5e9eaf126"\n ` to the beginning of the struct and
# convert result to string
(-?> target-zloc
# add various things to the left of :name
(j/insert-left [:keyword {} ":tag"])
(j/insert-left [:whitespace {} " "])
(j/insert-left [:string {} `"5e9eaf126"`])
(j/insert-left [:whitespace {} "\n"])
(j/insert-left [:whitespace {} " "])
# zip back up to the root
j/root
# convert to string of janet source
l/gen)
# =>
(string "{:name \"jeep\"\n"
" :version \"DEVEL\"\n"
" :description \"A Janet bundle manager\"\n"
" :author \"Michael Camilleri\"\n"
" :license \"MIT\"\n"
" :url \"https://github.com/pyrmont/jeep\"\n"
" :repo \"git+https://github.com/pyrmont/jeep\"\n"
"\n"
" :vendored {\n"
" \"deps\" [\n"
" {:tag \"5e9eaf126\"\n"
" :name \"argy-bargy\"\n"
" :url \"https://github.com/pyrmont/argy-bargy\"\n"
" :prefix \"argy-bargy\"\n"
" :files [\"argy-bargy.janet\"\n"
" \"LICENSE\"]}]}\n"
"}")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment