Last active
November 13, 2017 16:03
-
-
Save mandubian/bba50d55f26fcd14e82e9c0c29854a57 to your computer and use it in GitHub Desktop.
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
// Fake Scalafix rule to rewrite Scala to CCC | |
// Just so that you catch the idea | |
final case class CCCRule(index: SemanticdbIndex) extends SemanticRule(index, "CCCRule") { | |
def convertSubTree(ctx: RuleCtx, v: Tree, tree: Tree): Tree = { | |
tree match { | |
// the identity morphism | |
case t@q"$x => ${y: Term.Name}" if (x.name.isEqual(y)) => | |
q"""K.id[${x.decltpe.get}]""" | |
// the plus function completely hardcoded and supposing we have CCC & CCCNumExt in the context | |
case t@q"$px => $py => $x + $y" => | |
q"""○(addC)(⨂(exl[${x.decltpe.get}, ${x.decltpe.get}])(exr[${px.decltpe.get}, ${py.decltpe.get}]))""" | |
} | |
override def fix(ctx: RuleCtx): Patch = { | |
val trees = convertTree(ctx, ctx.tree) | |
trees.map { case (tree, newTree) => ctx.replaceTree(tree, newTree.toString) }.asPatch | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment