Fix parser

I had a few problems with the code (that I did not manage to distil into a failing test, I’m afraid). It inserted results in the wrong place. When I tried to fix the problem, I got a headache trying to follow the `substr` contortions and why they were not working. So I rewrote it to be easier to follow and fixed it in the process.

Then I had to fix the tests also because the rely too closely on the way the chunk parser iterates. The tests should be done a little differently, but I couldn’t be bothered fixing them just for this.

(Also, the entire module needs a complete refactor. Instead of passing internal state around as “special” keys in the variable hash, there should be a proper context object and most of the methods should be moved to its class. But that is a much bigger job than I’m willing to take on here and now.)

(While we’re at it: it should parse expressions itself instead of `eval`ing them (yuck!). And nested conditionals are broken – to fix that it needs a state stack instead of a simple flag.)