I'm trying to avoid repetition of long quasiquotes in matches. So, I'd like to convert this:
def appendTree(clazz: ClassDef, tree: Tree): ClassDef =
clazz match {
case q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }" =>
q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats; ..$tree }"
}
to something like this:
val clazzQuote = "$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats }"
def appendTree(clazz: ClassDef, tree: Tree): ClassDef =
clazz match {
case q"$clazzQuote" =>
q"$mods class $tpname[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$parents { $self => ..$stats; ..$tree }"
}
A comparable example of what I'm trying to do with string interpolation:
val msg = "hello $name"
"hello world" match {
case s"$msg" => println(name) // I want this to output "world"
}
This example doesn't work either.
How can I do this? (or can I?)