Pattern matcher

I believe it should be good to go.
Ready for review.
@adriaanm could you also have a look? as history is long and first pat-mat related commits aren't intelligent, I believe it would be better to start looking from last commits.