Refactor the parser into a base class.