The parser as it is functional but brittle. It needs to be rewritten as library code with exceptions, context managers and other abstracted schemes.