Compiling template engine based on pattern matching