Refactor pattern substitution.
Added PatternTransformer.