当前位置: 首页>>代码示例>>C#>>正文


C# TemplateGroup.DefineTemplate方法代码示例

本文整理汇总了C#中Antlr4.StringTemplate.TemplateGroup.DefineTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateGroup.DefineTemplate方法的具体用法?C# TemplateGroup.DefineTemplate怎么用?C# TemplateGroup.DefineTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Antlr4.StringTemplate.TemplateGroup的用法示例。


在下文中一共展示了TemplateGroup.DefineTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestIndirectMap

 public void TestIndirectMap()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("a", "[<x>]", new string[] { "x" });
     group.DefineTemplate("test", "hi <names:(templateName)()>!", new string[] { "names", "templateName" });
     Template st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     st.Add("templateName", "a");
     string expected =
         "hi [Ter][Tom][Sumana]!";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:TestIndirectionAndEarlyEval.cs

示例2: ToListString

 public static string ToListString(this IList list)
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("listTemplate", "[<list:{x|<x>}; separator=\", \">]", new string[] { "list" });
     group.RegisterRenderer(typeof(IList), new CollectionRenderer());
     Template st = group.GetInstanceOf("listTemplate");
     st.Add("list", list);
     return st.Render();
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:9,代码来源:ListExtensions.cs

示例3: TestMissingDictionaryValue2

 public void TestMissingDictionaryValue2()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("test", "<if(m.foo)>[<m.foo>]<endif>", new string[] { "m" });
     Template t = group.GetInstanceOf("test");
     t.Add("m", new Dictionary<string, string>());
     string expecting = "";
     string result = t.Render();
     Assert.AreEqual(expecting, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:10,代码来源:TestNullAndEmptyValues.cs

示例4: TestEvalSTIteratingSubtemplateInSTFromAnotherGroup

        public void TestEvalSTIteratingSubtemplateInSTFromAnotherGroup()
        {
            ErrorBuffer errors = new ErrorBuffer();
            TemplateGroup innerGroup = new TemplateGroup();
            innerGroup.Listener = errors;
            innerGroup.DefineTemplate("test", "<m:samegroup()>", new string[] { "m" });
            innerGroup.DefineTemplate("samegroup", "hi ", new string[] { "x" });
            Template st = innerGroup.GetInstanceOf("test");
            st.Add("m", new int[] { 1, 2, 3 });

            TemplateGroup outerGroup = new TemplateGroup();
            outerGroup.DefineTemplate("errorMessage", "<x>", new string[] { "x" });
            Template outerST = outerGroup.GetInstanceOf("errorMessage");
            outerST.Add("x", st);

            string expected = "hi hi hi ";
            string result = outerST.Render();

            Assert.AreEqual(errors.Errors.Count, 0); // ignores no such prop errors

            Assert.AreEqual(expected, result);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:22,代码来源:TestSubtemplates.cs

示例5: TestAttrSeparator

 public void TestAttrSeparator()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("test", "hi <name; separator=sep>!", new string[] { "name", "sep" });
     Template st = group.GetInstanceOf("test");
     st.Add("sep", ", ");
     st.Add("name", "Ter");
     st.Add("name", "Tom");
     st.Add("name", "Sumana");
     string expected = "hi Ter, Tom, Sumana!";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:TestOptions.cs

示例6: TestEmptyListGetsNoOutput

 public void TestEmptyListGetsNoOutput()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("test",
         "begin\n" +
         "<users:{u | name: <u>}; separator=\", \">\n" +
         "end\n", new string[] { "users" });
     Template t = group.GetInstanceOf("test");
     t.Add("users", new List<string>());
     string expecting = "begin" + newline + "end";
     string result = t.Render();
     Assert.AreEqual(expecting, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:TestNullAndEmptyValues.cs

示例7: TestEvalSTFromAnotherGroup

        public void TestEvalSTFromAnotherGroup()
        {
            ErrorBuffer errors = new ErrorBuffer();
            TemplateGroup innerGroup = new TemplateGroup();
            innerGroup.Listener = errors;
            innerGroup.DefineTemplate("bob", "inner");
            Template st = innerGroup.GetInstanceOf("bob");

            TemplateGroup outerGroup = new TemplateGroup();
            outerGroup.Listener = errors;
            outerGroup.DefineTemplate("errorMessage", "<x>", new string[] { "x" });
            outerGroup.DefineTemplate("bob", "outer"); // should not be visible to test() in innerGroup
            Template outerST = outerGroup.GetInstanceOf("errorMessage");
            outerST.Add("x", st);

            string expected = "inner";
            string result = outerST.Render();

            Assert.AreEqual(errors.Errors.Count, 0); // ignores no such prop errors

            Assert.AreEqual(expected, result);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:22,代码来源:TestSubtemplates.cs

示例8: TestIllegalOption

 public void TestIllegalOption()
 {
     ErrorBuffer errors = new ErrorBuffer();
     TemplateGroup group = new TemplateGroup();
     group.Listener = errors;
     group.DefineTemplate("test", "<name; bad=\"ugly\">", new string[] { "name" });
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     string expected = "Ter";
     string result = st.Render();
     Assert.AreEqual(expected, result);
     expected = "[test 1:7: no such option: bad]";
     Assert.AreEqual(expected, errors.Errors.ToListString());
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:14,代码来源:TestOptions.cs

示例9: TestDoubleListApplyWithNullValueAndNullOption

 public void TestDoubleListApplyWithNullValueAndNullOption()
 {
     // first apply sends [Template, null, Template] to second apply, which puts [] around
     // the value.  This verifies that null not blank comes out of first apply
     // since we don't get [null].
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("test", "<name:{n | <n>}:{n | [<n>]}; null=\"n/a\">", new string[] { "name" });
     Template st = group.GetInstanceOf("test");
     st.Add("name", "Ter");
     st.Add("name", null);
     st.Add("name", "Sumana");
     string expected = "[Ter]n/a[Sumana]";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:TestOptions.cs

示例10: TestParallelMap

 public void TestParallelMap()
 {
     TemplateGroup group = new TemplateGroup('$', '$');
     group.DefineTemplate("test", "hi $names,phones:{n,p | $n$:$p$;}$", new string[] { "names", "phones" });
     Template st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     st.Add("phones", "x5001");
     st.Add("phones", "x5002");
     st.Add("phones", "x5003");
     string expected =
         "hi Ter:x5001;Tom:x5002;Sumana:x5003;";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:jamilgeor,项目名称:antlrcs,代码行数:16,代码来源:TestDollarDelimiters.cs

示例11: TestEmptyExpr2

 public void TestEmptyExpr2()
 {
     string template = "hi <> ";
     TemplateGroup group = new TemplateGroup();
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     try
     {
         group.DefineTemplate("test", template);
     }
     catch (TemplateException)
     {
     }
     string result = errors.ToString();
     string expected = "test 1:3: doesn't look like an expression" + newline;
     Assert.AreEqual(expected, result);
 }
开发者ID:antlr,项目名称:antlrcs,代码行数:17,代码来源:TestSyntaxErrors.cs

示例12: TestWeirdChar2

 public void TestWeirdChar2()
 {
     string template = "\n<\\\n";
     TemplateGroup group = new TemplateGroup();
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     try
     {
         group.DefineTemplate("test", template);
     }
     catch (TemplateException)
     {
     }
     string result = errors.ToString();
     string expected = "test 1:2: invalid escaped char: '<EOF>'" + newline +
                       "test 1:2: expecting '>', found '<EOF>'" + newline;
     Assert.AreEqual(expected, result);
 }
开发者ID:antlr,项目名称:antlrcs,代码行数:18,代码来源:TestSyntaxErrors.cs

示例13: TestParallelMapWith3Versus2Elements

 public void TestParallelMapWith3Versus2Elements()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("test", "hi <names,phones:{n,p | <n>:<p>;}>", new string[] { "names", "phones" });
     Template st = group.GetInstanceOf("test");
     st.Add("names", "Ter");
     st.Add("names", "Tom");
     st.Add("names", "Sumana");
     st.Add("phones", "x5001");
     st.Add("phones", "x5002");
     string expected =
         "hi Ter:x5001;Tom:x5002;Sumana:;";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:TestCoreBasics.cs

示例14: TestUnterminatedExpr

 public void TestUnterminatedExpr()
 {
     string template = "hi <t()$";
     TemplateGroup group = new TemplateGroup();
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     try
     {
         group.DefineTemplate("test", template);
     }
     catch (TemplateException)
     {
     }
     string result = errors.ToString();
     string expected = "test 1:7: invalid character '$'" + newline +
         "test 1:7: invalid character '<EOF>'" + newline +
         "test 1:7: premature EOF" + newline;
     Assert.AreEqual(expected, result);
 }
开发者ID:antlr,项目名称:antlrcs,代码行数:19,代码来源:TestSyntaxErrors.cs

示例15: TestWeirdChar

 public void TestWeirdChar()
 {
     string template = "   <*>";
     TemplateGroup group = new TemplateGroup();
     ErrorBuffer errors = new ErrorBuffer();
     group.Listener = errors;
     try
     {
         group.DefineTemplate("test", template);
     }
     catch (TemplateException)
     {
     }
     string result = errors.ToString();
     string expected = "test 1:4: invalid character '*'" + newline +
                       "test 1:0: this doesn't look like a template: \"   <*>\"" + newline;
     Assert.AreEqual(expected, result);
 }
开发者ID:antlr,项目名称:antlrcs,代码行数:18,代码来源:TestSyntaxErrors.cs


注:本文中的Antlr4.StringTemplate.TemplateGroup.DefineTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。