tree-sitter-scala
tree-sitter-scala copied to clipboard
Folding for nested `def`s (or something) in Scala 3
Folding does not quite work on nested def
I encountered; Forgive the code not compiling — I tried to minimize it aggressively and quickly, rather than make it compile. The fold that is supposed to be around def of(base: BaseT)
terminates only after it encounters the case class. Screenshot:
Code:
package bla
object DevRun:
trait TreeishSuper:
def of(base: BaseT): T =
def getterIfNotPresent =
NodeTreeish.childrenOf(base) match
case Vector() => construct(base, Vector())
case children @ _ => construct(base, children.toVector.map{of(_)})
cache.getOrElseUpdate(base, getterIfNotPresent)
case class Plan(val instructions: Vector[PlanInstruction], val targetNodes: Vector[NT]):
val inputs_targets = for { t <- targetNodes; i <- pushingNodes } yield (i,t)
val pushingToOutputs = for { t <- graph.outputNodes; i <- pushingNodes } yield (i,t)
val allWalksWithActives = shape.graph.dag.linearWalksAtoB.filter{ w => w.toList.exists{targetNodes.contains(_) && pushingNodes.contains(w.origin) }}
end DevRun
Note that this happens even if the whole file compiles.