nit: that would be really great to improve error reporting when the parser get an unexpected pattern.
Here if the regexp fails, we will throw an internal exception instead of saying "hey there is something wrong with a section declaration at this line".
But we can keep such improvement for a followup as you just mimic what python code was doing.