-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
ducktape/src/main/scala/io/github/arainko/ducktape/PathMatcher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.arainko.ducktape | ||
|
||
import scala.quoted.* | ||
import io.github.arainko.ducktape.internal.macros.DebugMacros | ||
import scala.collection.mutable.ListBuffer | ||
import scala.annotation.tailrec | ||
|
||
object PathMatcher { | ||
// inline def run[A](inline expr: Selector ?=> A => Any) = ${ readPath('expr) } | ||
|
||
def readPath[A: Type](expr: Expr[Selector ?=> A => Any])(using Quotes): List[String | Type[?]] = { | ||
import quotes.reflect.{ Selector as _, * } | ||
|
||
@tailrec | ||
def recurse(using Quotes)(acc: List[String | Type[?]], term: quotes.reflect.Term): List[String | Type[?]] = { | ||
import quotes.reflect.* | ||
|
||
given Printer[TypeRepr] = Printer.TypeReprShortCode | ||
|
||
term match { | ||
case Inlined(_, _, tree) => | ||
recurse(acc, tree) | ||
case Lambda(_, tree) => | ||
recurse(acc, tree) | ||
case Block(_, tree) => | ||
recurse(acc, tree) | ||
case Select(tree, name) => | ||
recurse(name :: acc, tree) | ||
case TypeApply(Apply(TypeApply(Select(Ident(_), "at"), _), tree :: Nil), tpe :: Nil) => | ||
recurse(tpe.tpe.asType :: acc, tree) | ||
case Ident(_) => acc | ||
case other => report.errorAndAbort(other.show(using Printer.TreeShortCode)) | ||
} | ||
} | ||
recurse(Nil, expr.asTerm) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters