refactoring to support mutiple grammars
... trying to not allocate buffers repeatedly, but os x is being really
stupid about it.