Miksilo icon indicating copy to clipboard operation
Miksilo copied to clipboard

Allow using Scala traits to access and create AST nodes in an idiomatic way

Open keyboardDrummer opened this issue 2 years ago • 0 comments

Enable defining delta's like this:

trait Compilation {
  def visit<T>(action: T => ()) {
  }
  def getFactory<T>: T
}

trait BlockStatementFactory {
  def create(statements: Seq[Node]): BlockStatement
}

trait BlockStatement {
  def statements: Seq[Node]
  def statements_(statements: Seq[Node]): Unit
}

object BlockDelta extends LanguageExtension {

  def factoryType = typeTag[BlockStatementFactory]

  def tranformProgram(compilation: Compilation) {
    val blockFactory = compilation.getFactory(factoryType)
    program.visit<BlockStatement>(block => {
      val newStatements = blockFactory.create(Seq.empty[Node])
      block.statements = Seq(newStatements);
    });
  }
}

keyboardDrummer avatar Jan 04 '22 14:01 keyboardDrummer