cursive
cursive copied to clipboard
Discard (#_) used before metadata results in incorrect comment highlighting
From https://clojurians.slack.com/archives/C0744GXCJ/p1644931688839219
Currently when discard (#_) is used before a metadata literal, it results in only the metadata literal being highlighted as a comment:

This is incorrect in Clojure source files as Clojure discards the form the metadata applies to (which is the form after the metadata literal), so in the example in the screenshot, [chan] should also be highlighted as a comment.
Colin: Does that mean that
#_ ^:foo bar bazwould returnbazwithout meta, or that the meta would apply tobarand would get dropped?Alex Miller:
#_ says read the next thing and drop it ^:foo says here's some meta, read the next thing and give it that meta read bar symbol ... meta is applied to bar ... #_ drops bar w/meta read baz symbol
For edn files the matter is somewhat more complex. The edn format documentation does not mention metadata at all and does not appear to allow any tokens to begin with ^. The Clojure implementation of edn read however has an extension which handles metadata literals just like Clojure itself:
(clojure.edn/read-string "[^asdf foo]")
=> [foo]
(clojure.edn/read-string "[#_^asdf foo]")
=> []
(clojure.edn/read-string "^asdf foo")
=> foo
(meta (clojure.edn/read-string "^asdf foo"))
=> {:tag asdf}
(prn-str (clojure.edn/read-string "^asdf foo"))
=> "foo\n"
(pr-str (clojure.edn/read-string "^asdf foo"))
=> "foo"