This is much cleaner and now that all the types are there properly, doing a parser generator should be easier.