Pre sip Scala external preprocessors

I am sorry that Rewrite Methods is dropped, so just to raise the mood I propose to consider a crazy idea :slight_smile:

When I think about white box macros I think about preprocessors like SQLJ( Because type providers can be made by code generation. Optimization can be made by black box macros, extension can be made by Scala dsl and so on.

However, when we need deep integration with non-object\procedural language we need white box macros.

Unfortunately, it is very hard to implement :frowning:

However, we still need it. May be instead of dreams about super white box, the integration with external preprocessors can be implemented.

For example

 implicit class SqlHelper(val sc: StringContext) extends AnyVal {

 // some.pkg.SomeClass is available java class in compilation

// it has method generate which return bytecode of java interface
// sc.sourceString is ”select a,b,c from table”

// X  is generated trait\interface  by SomeClass

type X = macro("some.pkg.SomeClass", sc.sourceString)

def sql[X](args: Any*) (implicit tag: TypeTag[X]): Query[X] = new Query(runtimeFactory.createImplementatin(tag.runtimeClass),sc)


for(rs<-Sql”select a,b,c from table”){


some.pkg.SomeClass.generate is a plain java procedure which receive string and return bytearray so it can be executed at any time.

The interface implementation can be made in runtime.

Therefore, it may be easy to implement and can give the ability to use external preprocessors in Scala.

I really like the idea. A far as I known, Scalameta guys are seeking for a solution for untyped AST transformation as well. Maybe you guys can work together.


1 Like

I think it would be better to rename this topic to “Language injection”. I just have not enough right for that already.