-
Notifications
You must be signed in to change notification settings - Fork 24
Description
As reported by @rrudakov in this clojure-ts-mode issue, the current tree-sitter-clojure grammar might be seen to not properly handle return type metadata from a semantic perspective.
As a concrete example (slightly edited from the original), consider:
(defn to-string
^String
[arg]
(.toString arg))
^String
here refers to the return type of the function. A straight-forward interpretation might consider the metadata to not be for the argument vector [arg]
. (Possibly one could choose to see it that way though as argument information and return type information have to do with the input(s) and output(s) of a function and in some languages end up being expressed right next to each other.)
For reference, at clojure.org, this is currently documented at the Type Hints section of the Java Interop page:
For function return values, the type hint can be placed before the parameter vector:
(defn hinted-single ^String [])
-> #user/hinted-single
(defn hinted
(^String [])
(^Integer [a])
(^java.util.List [a & args]))
-> #user/hinted
In a comment in the aforementioned issue, an alternative approach to parsing metadata was mentioned:
I think having metadata as standalone nodes would solve a lot of code navigation issues at least in Emacs.
The clojure-ts-mode issue had this comment as well:
Expressions with metadata (BTW, I really don't like how the grammar works with metadata, it's pain to work with and causes more problems than benefits)
Additional details were elaborated upon in this comment.
So the proposed alternative approach for handling metadata may have multiple motivations.
I suspect this would involve a significant reworking of the grammar. May be creating a new grammar would allow additional improvements to be incorporated such as this issue as well as an additional point made about open
nodes [1].
[1] Also made in this comment.