use pattern matching for macro expansion
Merge pull request #936 from yilongli/use-pattern-matching-for-macro-expansion

use pattern matching for macro expansion