Skip to content

Instantly share code, notes, and snippets.

@deusaquilus
Last active May 19, 2021 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deusaquilus/717fb183b42095ffde2fdc97b20a3c50 to your computer and use it in GitHub Desktop.
Save deusaquilus/717fb183b42095ffde2fdc97b20a3c50 to your computer and use it in GitHub Desktop.
Delegating Parsing Function
// 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