Relocate some pattern parsing code