turned pattern handling code into a legion of polymorphic classes; some work on special cases still pending.

corresponds to Perforce change 6154.