Rewrite query parser to use ${} and allow $N

First step towards supporting prepared queries