Last active
May 19, 2021 04:06
-
-
Save deusaquilus/717fb183b42095ffde2fdc97b20a3c50 to your computer and use it in GitHub Desktop.
Delegating Parsing Function
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
// Say we have something like this: | |
case class OperationsParser(root: Parser[Ast] = Parser.empty)(override implicit val qctx: Quotes) extends Parser.Clause[Ast] with ComparisonTechniques { | |
def delegate: PartialFunction[Expr[_], Ast] = { | |
case ... | |
} | |
} | |
// Just do this: | |
case class OperationsParser(root: Parser[Ast] = Parser.empty)(override implicit val qctx: Quotes) extends Parser.Clause[Ast] with ComparisonTechniques { | |
def delegate: PartialFunction[Expr[_], Ast] = { | |
del.compose(PartialFunction.fromFunction( | |
(expr: Expr[_]) => { | |
// Now you can do things like print something when it comes in to this parser | |
println(s"I am trying to parser this expression: ${io.getquill.util.Format.Expr(expr)}") | |
expr | |
} | |
)) | |
} | |
def del: PartialFunction[Expr[_], Ast] = { | |
case ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment