ClojureDart `#/` parametrized type support
NoahTheDuke opened this issue · comments
Is your feature request related to a problem? Please describe.
ClojureDart has a small reader dispatch extension, /
, which adds support for parametrized types. It's implemented with a data reader (source).
The data reader provides support in two different ways:
- the base is
#/[List int]
is transformed to^{:type-params [int]} List
. It's like the meta reader, and it works recursively. - There's also support for functions with
->
:#/(int -> Null)
is transformed to^{:params-types [Null int] :type-params nil} dart:core/Function
.
(dart-type-params-reader '[List])
; List
(dart-type-params-reader '[List [List int]])
; ^{:type-params (^{:type-params (int)} List)} List
(dart-type-params-reader '( int -> Never))
; ^{:params-types (Never), :type-params nil} dart:core/Function
(dart-type-params-reader '(dynamic -> [List int]))
; ^{:params-types (^{:type-params (int)} List dynamic), :type-params nil} dart:core/Function
Describe the solution you'd like
Edamame can read ClojureDart files without throwing an exception.
Describe alternatives you've considered
Fork edamame to add support, do nothing.
Additional context
I think that supporting a subset of this is a pretty simple extension and have a working branch that does so. I'm willing to open a PR with the change if so desired.
My subset would be the :type-params
version, and leave off the function-specific parsing. #/(-> List)
would be rendered as ->
with metadata {:type-params [List]}
.
You can provide data readers like so:
user=> (e/parse-string "#/[List int]" {:readers {'/ identity}})
[List int]
Edamame supports JVM Clojure and ClojureScript, but other dialects can be supported through these options.
Note that edamame doesn't even read CLJS files when used from the JVM. It only provides the expected defaults for the environment it's used it. But it can be easily configured to read CLJS files in a JVM, that's just up to the user via the configuration. So until we support ClojureDart as a host from which edamame is used, it just doesn't make sense to add support for the above as a built-in thing.
That's interesting about CLJS. What features aren't supported in JVM Edamame?
Would you accept a pr for adding documentation to the readme about adding this support?
Yeah, let's document it explicitly, good idea
For example, ClojureScript uses #js {:a 1}
, which is not enabled by default in JVM Clojure. But you can do this through configuration.