Add support for counting syntactic matches in a macro definition

This is a proposed solution for https://github.com/mozilla/rust/issues/12782.