DO NOT REVIEW THIS CODE BY HAND
This parsing code is quite complex and not easy to hand-modify.
The easiest way to iterate is to add unit tests and have Codex fix the implementation.
To encourage this, the tests have been put directly below this function rather than at the bottom of the