Make the code for grammar data processing common