Is there any way to use untyped AST? #12539
Answered
by
giiita
scf37
asked this question in
Metaprogramming
-
I.e. My use caseGiven class Scala2 solutionparse scala source file, extract string expressions, generate untyped AST: val left = c.universe.TermName(leftStr)
val right = c.universe.TermName(rightStr)
q"$left.$right" Then generate seq of all expressions and filter them at runtime q"""
Seq(..$expressions)
.filter{v: Any => v.isInstanceOf[T]}
.asInstanceOf[Seq[T]]""" Scala3 ?
|
Beta Was this translation helpful? Give feedback.
Answered by
giiita
May 27, 2021
Replies: 1 comment
-
This question is probably related to this one. However, it is possible to refer to any expression in call site, as in the example below. object Main extends App {
val member: String = "I am Main member"
println(Macro.getMember())
} import scala.quoted._
object Macro {
def getMember()(using q: Quotes): Expr[String] = {
Select.unique(This(q.reflect.Symbol.spliceOwner.owner), "member").asExprOf[String]
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nicolasstucki
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This question is probably related to this one.
#12500
However, it is possible to refer to any expression in call site, as in the example below.
It seems that it is no longer possible to refer to it visually from within
Quasiquotes
as before.