Created
June 18, 2020 07:21
-
-
Save okram/e8d47df897a10a69db98e90172d4153e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@scala.annotation.tailrec | |
def fetchOption[A <: Obj](obj: Obj, label: String): Option[A] = { | |
obj match { | |
case x if x.root => None | |
case x if x.via._2.op == Tokens.to && x.via._2.arg0[StrValue].g == label => obj match { | |
case _: Value[Obj] => Some(x.via._1.asInstanceOf[A]) | |
case _: Type[Obj] => Some(x.via._1.range.from(label).asInstanceOf[A]) | |
} | |
case x if x.via._2.op == Tokens.rewrite && x.via._2.arg0[Obj].name == label => Some(Inst.resolveArg(obj, x.via._2.arg0[A])) | |
case x if x.via._2.op == Tokens.define && x.via._2.arg0[Obj].name == label => Some(Inst.resolveArg(obj, x.via._2.arg0[A].named(baseName(x.via._2.arg0[A])))) | |
case x => fetchOption(x.via._1, label) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment