Template parser split

This a is rebased of #180.
I also removed the changes needed to be compatible with Scala 2.9.