I want to transform Scala XML literals with a macro. (Not a string literal with XML but actual XML literals). As far as I understand, XML literals are not actually built into the language on the AST level but are desugared in the parser. Interestingly though, this does work:
case q"<specificTag></specificTag>" => ... // succeeds for specificTag with no
// attributes and children
But obviously, this is totally useless because it is impossible to match arbitrary xml that way. Something like
case q"<$prefix:$label ..$attrs>$children</$prefix:$label>" => ...
can not work because we would have to bind the same variable twice in a pattern.
Printing out the tree of such an xml literal expression actually gives the desugared version. For example.
new _root_.scala.xml.Elem(null,"specificTag",_root_.scala.xml.Null,$scope,false)
But trying to match this fails:
case q"new _root_.scala.xml.Elem(..$params)" => ... // never succeeds
I am confused! My question is: Is there a way to reliably match arbitrary xml litarals in scala macros? Additionally: Why are they supported in quasiquotes for constant xml and not for the desugared value after all?