Skip to content

Add support for Clojure 1.12 vector metadata #286

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

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ A release with known breaking changes is marked with:
// (adjust these in publish.clj as you see fit)
=== Unreleased

* bump `org.clojure/tools.reader` to version `1.4.2` (@lread)
* bump `org.clojure/tools.reader` to version `1.4.2`
(@lread)
* `sexpr` now 1) expands tag metadata to its long form 2) throws on invalid metadata
https://github.com/clj-commons/rewrite-clj/issues/280[#280]
(@lread)
* Add support for Clojure 1.12 vector metadata
https://github.com/clj-commons/rewrite-clj/issues/279[#279]
(@lread)
* `rewrite-clj.paredit/barf-forward` on zipper created with `:track-position? true` now correctly barfs when current node has children
https://github.com/clj-commons/rewrite-clj/issues/245[#245]
(@lread, thanks for the issue @p4ulcristian!)
Expand Down
1 change: 1 addition & 0 deletions src/rewrite_clj/node/meta.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(keyword? mta) {mta true}
(symbol? mta) {:tag mta}
(string? mta) {:tag mta}
(vector? mta) {:param-tags mta}
:else (throw (ex-info "Metadata must be a map, keyword, symbol or string" {}))))))
(length [_node]
(+ (count prefix) (node/sum-lengths children)))
Expand Down
68 changes: 68 additions & 0 deletions test/rewrite_clj/parser_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,74 @@
(is (= 'foo (node/sexpr n)) s)
(is (= {:tag "MyType"} (meta (node/sexpr n))) s)))

(deftest t-parsing-clj-1-12-vector-metadata
(doseq [[s expected-meta expected-node]
[["^[a b c] foo"
{:param-tags '[a b c]}
(node/meta-node [(node/vector-node [(node/token-node 'a)
(node/spaces 1)
(node/token-node 'b)
(node/spaces 1)
(node/token-node 'c)])
(node/spaces 1)
(node/token-node 'foo)])]

["^[] foo"
{:param-tags []}
(node/meta-node [(node/vector-node [])
(node/spaces 1)
(node/token-node 'foo)])]

["^[_ _] foo"
{:param-tags '[_ _]}
(node/meta-node [(node/vector-node [(node/token-node '_)
(node/spaces 1)
(node/token-node '_)])
(node/spaces 1)
(node/token-node 'foo)])]

["^{:param-tags [a b c]} foo"
{:param-tags '[a b c]}
(node/meta-node
[(node/map-node [(node/keyword-node :param-tags)
(node/spaces 1)
(node/vector-node [(node/token-node 'a)
(node/spaces 1)
(node/token-node 'b)
(node/spaces 1)
(node/token-node 'c)])])
(node/spaces 1)
(node/token-node 'foo)])]

["#^[a b c] foo"
{:param-tags '[a b c]}
(node/raw-meta-node [(node/vector-node [(node/token-node 'a)
(node/spaces 1)
(node/token-node 'b)
(node/spaces 1)
(node/token-node 'c)])
(node/spaces 1)
(node/token-node 'foo)])]

["#^{:param-tags [a b c]} foo"
{:param-tags '[a b c]}
(node/raw-meta-node
[(node/map-node [(node/keyword-node :param-tags)
(node/spaces 1)
(node/vector-node [(node/token-node 'a)
(node/spaces 1)
(node/token-node 'b)
(node/spaces 1)
(node/token-node 'c)])])
(node/spaces 1)
(node/token-node 'foo)])]]

:let [n (p/parse-string s)]]
(is (= expected-node n) s)
(is (= s (node/string n)))
(is (= 'foo (node/sexpr n)) s)
(is (= expected-meta (meta (node/sexpr n))) s)))

(deftest t-parsing-invalid-metadata
(let [s "^(list not valid) foo"
n (p/parse-string s)]
Expand Down