Parser

Here goes the cleaned up pull request. Sorry for the delay. It was a bit more complicated than I expected. Please review it and tell me something is wrong.