refactoring in GrammarFormatter