Last active
March 22, 2026 23:56
-
-
Save sogaiu/848140fe6b834d0469babc69c71ad141 to your computer and use it in GitHub Desktop.
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
| (comment | |
| (def path-str ":vendored 2 :tag") | |
| # bundle/info.jdn | |
| (def src | |
| `` | |
| {:name "ghost" | |
| :url "https://github.com/sogaiu/ghost" | |
| :repo "git+https://github.com/sogaiu/ghost" | |
| :vendored | |
| [{:name "some-bundle-bits" | |
| :url "https://github.com/sogaiu/some-bundle-bits" | |
| :tag "70409ab34b7c762118e0d31efaa4d2f01d46fecf" | |
| :paths [["sbb.janet" "bundle/"]]} | |
| {:name "jell" | |
| :url "https://github.com/sogaiu/jell" | |
| :tag "718464b8b94971fd8f9e984ca81d35e2c859546e" | |
| :paths [["jell" "bin/"]]} | |
| {:name "niche" | |
| :url "https://github.com/sogaiu/niche" | |
| :tag "7caf81f636bb97104aada6544219733b3c86badf" | |
| :paths [["niche.janet" "bin/"]]}]} | |
| ``) | |
| (def ds (parse src)) | |
| (def path (parse-all path-str)) | |
| # phase 1: ensure path makes sense for ds and obtain new path | |
| (def [value new-path] (get-via ds path)) | |
| # => | |
| ["7caf81f636bb97104aada6544219733b3c86badf" @[:vendored 2 :tag]] | |
| # phase 2: zipper traversal with edit | |
| (def zloc (j/zip-down (j/par src))) | |
| # first item in path to look for is :vendored | |
| (var cur-zloc (j/down-skip-wsc zloc)) | |
| (var cur-node (j/node cur-zloc)) | |
| (get cur-node 0) | |
| # => | |
| :keyword | |
| (get cur-node 2) | |
| # => | |
| ":name" | |
| (set cur-zloc (j/right-until cur-zloc | |
| |(match (j/node $) | |
| [:keyword _ ":vendored"] | |
| true | |
| # | |
| false))) | |
| (set cur-node (j/node cur-zloc)) | |
| # => | |
| [:keyword @{:bc 2 :bl 4 :bp 101 :ec 11 :el 4 :ep 110} ":vendored"] | |
| # found the keyword move to corresponding value | |
| (set cur-zloc (j/right-skip-wsc cur-zloc)) | |
| # tuple | |
| (set cur-node (j/node cur-zloc)) | |
| (get cur-node 0) | |
| # => | |
| :bracket-tuple | |
| # move down into value | |
| (set cur-zloc (j/down-skip-wsc cur-zloc)) | |
| (set cur-node (j/node cur-zloc)) | |
| (get cur-node 0) | |
| # => | |
| :struct | |
| # second path item, 2, so need to do right-skip-wsc twice | |
| (set cur-zloc (j/right-skip-wsc cur-zloc)) | |
| (set cur-zloc (j/right-skip-wsc cur-zloc)) | |
| (set cur-node (j/node cur-zloc)) | |
| (get cur-node 0) | |
| # => | |
| :struct | |
| # move down into struct | |
| (set cur-zloc (j/down-skip-wsc cur-zloc)) | |
| (set cur-node (j/node cur-zloc)) | |
| # => | |
| [:keyword @{:bc 4 :bl 13 :bp 420 :ec 9 :el 13 :ep 425} ":name"] | |
| # last path item, :tag | |
| (set cur-zloc (j/right-until cur-zloc | |
| |(match (j/node $) | |
| [:keyword _ ":tag"] | |
| true | |
| # | |
| false))) | |
| (set cur-node (j/node cur-zloc)) | |
| # => | |
| [:keyword @{:bc 4 :bl 15 :bp 479 :ec 8 :el 15 :ep 483} ":tag"] | |
| # found the keyword move to corresponding value | |
| (set cur-zloc (j/right-skip-wsc cur-zloc)) | |
| # target node | |
| (set cur-node (j/node cur-zloc)) | |
| # => | |
| [:string @{:bc 9 :bl 15 :bp 484 :ec 51 :el 15 :ep 526} | |
| `"7caf81f636bb97104aada6544219733b3c86badf"`] | |
| # can verify value against returned info from `get-via` | |
| value | |
| # => | |
| "7caf81f636bb97104aada6544219733b3c86badf" | |
| (= value | |
| (parse (get cur-node 2))) | |
| # => | |
| true | |
| (def e-zloc | |
| (j/replace cur-zloc | |
| [:string @{} `"9c2832d803b39f27ffd12d1a5fc82f3b83c64b4b"`])) | |
| (j/gen (j/root e-zloc)) | |
| # => | |
| `` | |
| {:name "ghost" | |
| :url "https://github.com/sogaiu/ghost" | |
| :repo "git+https://github.com/sogaiu/ghost" | |
| :vendored | |
| [{:name "some-bundle-bits" | |
| :url "https://github.com/sogaiu/some-bundle-bits" | |
| :tag "70409ab34b7c762118e0d31efaa4d2f01d46fecf" | |
| :paths [["sbb.janet" "bundle/"]]} | |
| {:name "jell" | |
| :url "https://github.com/sogaiu/jell" | |
| :tag "718464b8b94971fd8f9e984ca81d35e2c859546e" | |
| :paths [["jell" "bin/"]]} | |
| {:name "niche" | |
| :url "https://github.com/sogaiu/niche" | |
| :tag "9c2832d803b39f27ffd12d1a5fc82f3b83c64b4b" | |
| :paths [["niche.janet" "bin/"]]}]} | |
| `` | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment