Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
keyboardDrummer opened this issue Jan 4, 2022 · 0 comments

Comments

@keyboardDrummer
Copy link
Owner

keyboardDrummer commented Jan 4, 2022

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);
    });
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant