Using a library such as Parsec, Attoparsec, Megaparsec, etc. could greatly improve the readability of the parsing logic.