File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ List((a @ Extractor((b @ Extractor((c @ _))))))
2
+ List((b @ Extractor((c @ _))))
3
+ List((c @ _))
Original file line number Diff line number Diff line change
1
+ import scala .reflect .macros .WhiteboxContext
2
+ import language .experimental .macros
3
+
4
+ object Extractor {
5
+ def unapply (x : Any ): Any = macro unapplyImpl
6
+ def unapplyImpl (c : WhiteboxContext )(x : c.Tree ) = {
7
+ val st = c.universe.asInstanceOf [reflect.internal.SymbolTable ]
8
+ import st ._
9
+ val subpatterns = x.attachments.get[SubpatternsAttachment ].get.patterns
10
+ q """
11
+ new {
12
+ def isEmpty = false
13
+ def get = ${subpatterns.toString}
14
+ def unapply(x: Any) = this
15
+ }.unapply( ${x.asInstanceOf [st.Tree ]})
16
+ """ .asInstanceOf [c.Tree ]
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ object Test extends App {
2
+ 42 match {
3
+ case Extractor (a @ Extractor (b @ Extractor (c))) => println(a); println(b); println(c)
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments