mostly copied from parse_script but with better handling of ?,.,!
i am sufficiently happy with this right now, but it could benefit from additional tweaking in future