blob: 0f30862347b683ca3cd75300546259ffde6b46f1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
import scala.reflect.macros.whitebox.Context
import language.experimental.macros
object Extractor {
def unapply(x: Any): Any = macro unapplyImpl
def unapplyImpl(c: Context)(x: c.Tree) = {
import c.universe._
import internal._
val pos = subpatterns(x).get.head.pos
q"""
new {
def isEmpty = false
def get = ${"The width of the subpattern is: " + (pos.end - pos.start + 1)}
def unapply(x: Any) = this
}.unapply($x)
"""
}
}
|