Guidance for the builder feature #8
Replies: 2 comments 5 replies
-
The "magic" that transforms the input into a compiled result is parseArguments. More specifically Swift MacrosWhile Swift Macros are powerful, in their current form they are very limited. When expanding a macro, you get a syntax representation of the parameters, not an exact 1-for-1 representation. You need to manually convert them into a system that best fits your usage. For my usage (Swift HTMLKit) I basically identify whether each element in the macro's innerHTML is an For implicit data we only get the declaration representation of the referenced data, which is only the name of the variable. We literally have no way in knowing what the data is, just that it is a declaration reference. A lot of tedious work would need to be created to even check if certain inputs can be promoted or not, which is why I chose to just use PromotionThe reason why I added a system of promoting certain interpolation to an equivalent A recent addition to I have added an experimental Explicit vs Implicit dataExplicit data is any data that you explicitly type. Implicit data is a reference to any data. // Explicit
let _:String = #html("<div></div>") // no promotion necessary
// Implicit
let string:String = "<div></div>"
let _:String = #html(string) // currently impossible to promote
// Promotion
let _:String = #html("\("<div></div>")") // we can promote it because it is explicitly typed |
Beta Was this translation helpful? Give feedback.
-
I will be refactoring how the content is parsed and handled by the macro expansion, and will be utilizing |
Beta Was this translation helpful? Give feedback.
-
I'm trying to understand how do the macros "know" what can be expanded statically and what needs interpolation. Things are working great since your recent commits with the trivial builder, but ideally there should be a way of executing the result of a builder and work on that, not unlike executing a function that returns HTMLElement and work on that, instead of assuming interpolation is always needed. I am hoping that "fixing" the latter will also fix the former; currently
expands to
but does it have to?
What's the "magic" that transforms
#html(tr(td())) as String
into"<tr><td></td></tr>"
? You describe this as "promotion" in some places and I suspect it has to do with the initialiser that takes macro context arguments, but I haven't really figured this out. Pointers, tips, guidance and hand-holding are welcome :)Beta Was this translation helpful? Give feedback.
All reactions