improvements for grammar extraction

While cleaning up my repos I discovered this commit. Somehow it got lost.
Back then I introduced TERM for grammar terminals to separate meaning from style with grammar extraction in mind.
Not sure what to do with it so I opened this PR fwiw.