Some parser refactoring.

* Move token cursor functions into token stream class.
* Extract a parser base class.
Make type/pattern parsing less monolithic.