Quote-do, and then template + getAst seems very useful to easily generate AST. It's both easy to write and easy to read. It has some limits but it's sufficient often enough.
My question is: would a reverse functionality be useful too? I was thinking about writing ast-match functionality, which would bind escaped value and any inject declaration (as backticks work a bit differently in variable declarations). It should work a bit like a pegs match:
template myVar() =
var nice = "hack"
template varDeclPattern() =
var name {.inject.} = `value`
if getAst(nice()) =~ getAst(varDeclPattern()):
echo "Initialized variable `$1` with `$2`" % [name.repr, value.repr]
else:
echo "Not a variable declaration"
# outputs:
# Initialized variable `nice` with `"hack"`
No untyped as an argument to not overload other =~ operators, like pegs' one.
Would you guys consider it useful?