Quasiquotes

Other topics

Create a syntax tree with quasiquotes

Use quasiquotes to create a Tree in a macro.

object macro {
  def addCreationDate(): java.util.Date = macro impl.addCreationDate
}

object impl {
  def addCreationDate(c: Context)(): c.Expr[java.util.Date] = {
    import c.universe._

    val date = q"new java.util.Date()" // this is the quasiquote
    c.Expr[java.util.Date](date)
  }
}

It can be arbitrarily complex but it will be validated for correct scala syntax.

Contributors

Topic Id: 4032

Example Ids: 14078

This site is not affiliated with any of the contributors.