Factor grammars into a separate document model