Extract parser

The parser seems to be a cohesive unit.  Put it in it’s own file.
Update the TODOs.
Get rid of console.log and replace with debug.