Rewrite grammar with nested tokens