Thank you for your replay, Andrey.
I don’t really need to be able to alter syntax, but what I would like to have is some form of general nested sytax that I can use for code generation. LISP, of course has S-expressions. Although most languages don’t have macros, Javascript has JSON that could be used for same purpose. XML could also work in theory but it is too verbose in practice. I believe Kotlin needs something like that. Perhaps we can use Builders to assist with code generation? Consider this example:
sql_macro( sql{ select{ fields{“id”, “name”, “address”, “age”} from{“users”} where{ “address =”, address } } } ) // I am not sure if this is correct Builder syntax but you get the idea
At compile time, macro should replace this with the statement:
sql("SELECT id, name, address, age FROM users WHERE adress = '${escape_quotes(address)}' ")
It should then log in to database to check if query makes sense and then let it compile.
I would also like to be able to use annotations as markers for AST transformation. When compiler sees some specific annotation it should transform code in specified way. For example when you put ‘singleton’ annotation in front of class declaration, compiler should add all code necessary to convert class to singleton pattern (I know that you don’t really need singleton pattern when you have functions.)
Finally, I think Kotlin should also support python-like triple quotes so you can add any string you want if you are so inclined.
Is any of this stuff planned?
It should alse be noted that Scala added macro system some time ago, although I don’t know what it can do syntax-vise. Resistance is futile
.