factor out parser code into a standalone, reusable module