Can I use dotty
macro staging to parse a string, generate code and run it at runtime?
I was thinking about build a schema and web query language that can be used in different ways: passed via REST, or statically constructed and verified at compile-time. This will require both modes of operation (runtime/compile-time) and being able to reuse parts of the macro code in both modes.
From my first analysis of dotty lang, it looks feasible; however, I haven't seen any way of parsing a string using a function signature like String => Expr[?]
. Is this possible?
Also, does these macros have the power to change the scala code semantics? For instance, I want to do something like this, directly in scala code:
val preparedQuery = db.query User | name == "Alex" | page 1 limit 10 {
(asc 1) name,
address { country, city }
roles { * }
}
I should also be able to perform the same query using a string:
val preparedQuery = db.parseQuery(" <the same query> ")