Provide hooks into the compiler so that you can extend java with a sub languages. Useful small sub languages could be
- multi line strings
- embedded sql statements
- reflection based dynamic method invocations
- embedded xml
in the top you would write
import language sql org.bla.sql.EmbeddedSql;
java would then be extended with some syntax to separate java and the extension languge so you could write something like
int zip=12345;
@xml.stream(System.out){
<names>
@java{
for (String name : @sql.query{select name from people where zip = @java.zip}) {
@xml{
<name>@java.name</name>
}
}
}
</names>
}
@<language id>.<construct>{ text until '}' }
@<language id>{ text until '}' }
@<language id>.<construct>{{ text until '}}' }}
@<language id>.<construct>{{{ text until '}}}' }}}
this syntax should be enough to separate other languages and java.
Maybe the languages can provide some information to tools so that eclipse can syntax hilight the embedded language. |