I previously implemented macros within Roslyn (the C# compiler) and there you could do SyntaxFactory.ParseExpression("your C# code here") (docs) to get the AST, which is a lot more convenient than generating the AST by hand.
Is this possible in Scala? It seems like it would lower the entry barrier to macros quite a bit. If not, what are the reasons?
Quotes with reflection API Reflection | Macros in Scala 3 | Scala Documentation - I believe that’s what you’re referring to. These are the most complex and at the same time give you the most powerful tools.
If the job can be done with inlined methods - go for it, otherwise if it can be done using only quotes use this one. Compile time reflection API and manual AST construction should be reserved only to the code that cannot be done using simpler methods.
The Scala 3 macros are hygienic these are typed and prevent you from doing silly mistakes, however they require a bit more of ceremony.
In Scala 2 we had String based quasi-quotes Introduction | Quasiquotes | Scala Documentation These were easy to write and easy to abuse and shot your foot. Also the constant pain of referring to every single type using the fully qualified type from the _root_ scope so that there would be no conflicts with symbols at the callsite.
What do you mean by “silly mistakes”? In C#, you would get an AST, then splice it back to the existing AST. The compiler then would typecheck it, resulting in compile-time errors if necessary.
Isn’t that the same process which is happening right now by hand-crafted AST? Is there something that prevents me from constructing terms that are invalid in the macro and the compiler has to still typecheck those and reject them?