Move grammar-related code to the grammar package