Cleanup range loop parsing.

This change factors out some code in the ugly parseSimpleStmt
function. The function still does too much, but I don't see a better
solution at the moment.