C# 未处理ANTLR TemplateException

C# 未处理ANTLR TemplateException,c#,antlr4,C#,Antlr4,我正在使用Antlr的字符串模板功能,发现以下错误: Antlr4.StringTemplate.Compiler.TemplateException was unhandled HResult=-2146233088 Message=Exception of type 'Antlr4.StringTemplate.Compiler.TemplateException' was thrown. Source=Antlr4.StringTemplate 使用代码: class Pro

我正在使用Antlr的字符串模板功能,发现以下错误:

Antlr4.StringTemplate.Compiler.TemplateException was unhandled
  HResult=-2146233088
  Message=Exception of type 'Antlr4.StringTemplate.Compiler.TemplateException' was thrown.
  Source=Antlr4.StringTemplate
使用代码:

class Program
{
    static void Main(string[] args)
    {
        var messageTemplate = "<table style=\'border-collapse: collapse; width: 100%\' dir=\'ltr\' cellspacing=\'0\'><tr style=\'background-color: #f8f8f9; border: thin #e8eaec solid\'><td style=\'font-family: Verdana; font-size: 12pt; background-color: #f8f8f9; border: thin #e8eaec solid; padding: 20px 20px 20px 20px\'>New Order for Vendor: <strong style=\'font-family: Verdana; font-size: 12pt;\'>%VendorName%</strong></td></tr><tr><td></td></tr><tr style=\'background-color: #f8f8f9; border: thin #e8eaec solid\'><td style=\'font-family: Verdana; font-size: 12pt; background-color: #f8f8f9; border: thin #e8eaec solid; padding: 20px 20px 20px 20px\'><table><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>Order Number: </td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%OrderNumber%</td></tr><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>State: </td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%CustomerAddressState%</td></tr><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>County:</td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%CustomerAddressCounty%</td></tr><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>Municipality:</td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%VendorCity%</td></tr><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>Borrower:</td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%Borrowers%</td></tr><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>Product Family:</td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%ProductFamily%</td></tr><tr><td style=\'font-family: Verdana; font-size: 12pt;\'>Price:</td><td width=\'2px\'></td><td style=\'font-family: Verdana; font-size: 12pt;\'>%Price%</td></tr></table></td></tr><tr><td></td></tr><tr><td></td></tr><tr> <td style=\'font-family: Verdana; font-size: 12pt; padding: 20px 20px 20px 20px\'><img src=\'https://www.americantitleinc.com/ati/Portals/0/WebLogo_V1.png\' width=\'250\' height=\'95\' border=\'0\' alt=\'American Title <br>Service Without Boundaries\'/></td> </tr></table>";

        var template = new Template(messageTemplate, '%', '%');
        var attributes = new Dictionary<string, object>
            {
                {"VendorName", "Vendor"},
                {"OrderNumber", "OrderNumber"},
                {"CustomerAddressState", "CustomAddressState"},
                {"CustomerAddressCounty", "CustomAddressCounty"},
                {"VendorCity", "VendorCity"},
                {"Borrowers", "Borrowers"},
                {"ProductFamily", "ProductFamily"},
                {"Price", 10.5d}
            };

        foreach (var key in attributes.Keys)
            template.Add(key, attributes[key]);

        var result = template.Render();
    }
}
类程序
{
静态void Main(字符串[]参数)
{
var messageTemplate=“供应商的新订单:%VendorName%订单号:%OrderNumber%State:%customeraddress%State:%country:%customeraddress%country:%VendorCity%借款人:%借款人%Product系列:%ProductFamily%Price:%Price%无边界服务\'/>”;
var-template=新模板(messageTemplate,“%”,“%”);
var属性=新字典
{
{“供应商名称”,“供应商”},
{“订单号”,“订单号”},
{“CustomerAddressState”,“CustomAddressState”},
{“CustomerAddressCounty”、“CustomAddressCounty”},
{“VendorCity”,“VendorCity”},
{“借款人”、“借款人”},
{“ProductFamily”,“ProductFamily”},
{“价格”,10.5d}
};
foreach(attributes.Keys中的var键)
添加(键,属性[key]);
var result=template.Render();
}
}

不幸的是,这个错误是非常非描述性的。

这里的问题是模板是HTML,它包含一个
%
符号,该符号也是用于分隔符的字符。可惜错误没有更直接地指定

将分隔符替换为
~
修复了该问题