Editing EDN through a syntax tree that keeps everything a reader throws away.
clojure.edn/read-string gives you data, and data has no comments, no key
order and no indentation - so no writer can put them back. The tree here
keeps whitespace, comments and #_ discards as nodes of their own, which
makes rendering it the exact original text and an edit a change to one node.
Nodes are plain maps:
{:type :whitespace :text " \n\n"} {:type :comment :text ";; why this is 3000"} {:type :token :text "8080"} {:type :map :open "{" :close "}" :children [...]} {:type :wrapper :text "#inst" :children [...]} ; #_ ^meta 'quote #tag
parse and render are inverses: (= s (render (parse s))) for any EDN.
Editing EDN through a syntax tree that keeps everything a reader throws away.
`clojure.edn/read-string` gives you data, and data has no comments, no key
order and no indentation - so no writer can put them back. The tree here
keeps whitespace, comments and `#_` discards as nodes of their own, which
makes rendering it the exact original text and an edit a change to one node.
Nodes are plain maps:
{:type :whitespace :text " \n\n"}
{:type :comment :text ";; why this is 3000"}
{:type :token :text "8080"}
{:type :map :open "{" :close "}" :children [...]}
{:type :wrapper :text "#inst" :children [...]} ; #_ ^meta 'quote #tag
`parse` and `render` are inverses: (= s (render (parse s))) for any EDN.(delete-in-str s path)EDN text with path removed, leaving the formatting around it alone.
EDN text with `path` removed, leaving the formatting around it alone.
(locate ast path)The get-in keys that reach the node holding the value at path, or nil.
The `get-in` keys that reach the node holding the value at `path`, or nil.
(parse s)EDN text as a tree of nodes. Nothing is discarded, so render reproduces the
input exactly.
EDN text as a tree of nodes. Nothing is discarded, so `render` reproduces the input exactly.
(set-in-str s path value)EDN text with path set to value, as an edit to one node of the tree.
Every comment, blank line and column outside that node is the text that was
already there.
EDN text with `path` set to `value`, as an edit to one node of the tree. Every comment, blank line and column outside that node is the text that was already there.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |