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


C# Antlr.StringTemplate.StringTemplateGroup.DefineTemplate方法代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {
            StringTemplateGroup group = new StringTemplateGroup("dummy");
            StringTemplate bold = group.DefineTemplate("bold", "<b>$attr$</b>");
            StringTemplate banner = group.DefineTemplate("banner", "the banner");
            StringTemplate st = new StringTemplate(group,
                "<html>\n" +
                "$banner(a=b)$" +
                "<p><b>$name$:$email$</b>" +
                "$if(member)$<i>$fontTag$member</font></i>$endif$");
            st.SetAttribute("name", "Terence");
            st.SetAttribute("name", "Tom");
            st.SetAttribute("email", "[email protected]");
            st.SetAttribute("templateAttr", bold);

            StringTemplateTreeView frame =
                new StringTemplateTreeView("StringTemplateTreeView Example", st);
            Application.Run(frame);
        }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:19,代码来源:StringTemplateViewer.cs

示例2: testListOfIntArrays

 public void testListOfIntArrays()
 {
 StringTemplateGroup group = new StringTemplateGroup("test", typeof(AngleBracketTemplateLexer));
 StringTemplate t = group.DefineTemplate("t", "<data:array()>");
 group.DefineTemplate("array", "[<it:element(); separator=\",\">]");
 group.DefineTemplate("element", "<it>");
 IList data = new ArrayList();
 data.Add(new int[] { 1, 2, 3 });
 data.Add(new int[] { 10, 20, 30 });
 t.SetAttribute("data", data);
 string expecting = "[1,2,3][10,20,30]";
 Assert.AreEqual(expecting, t.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:13,代码来源:TestStringTemplate.cs

示例3: testAlternativeWriter

 public virtual void testAlternativeWriter()
 {
 StringBuilder buf = new StringBuilder();
 IStringTemplateWriter w = new AlternativeWriter(buf);
 StringTemplateGroup group = new StringTemplateGroup("test");
 group.DefineTemplate("bold", "<b>$x$</b>");
 StringTemplate name = new StringTemplate(group, "$name:bold(x=name)$");
 name.SetAttribute("name", "Terence");
 name.Write(w);
 Assert.AreEqual(buf.ToString(), "<b>Terence</b>");
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:11,代码来源:TestStringTemplate.cs

示例4: testExprInParens

 public virtual void testExprInParens()
 {
     // specify a template to apply to an attribute
     // Use a template group so we can specify the start/stop chars
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     StringTemplate bold = group.DefineTemplate("bold", "<b>$it$</b>");
     StringTemplate duh = new StringTemplate(group, @"$(""blort: ""+(list)):bold()$");
     duh.SetAttribute("list", "a");
     duh.SetAttribute("list", "b");
     duh.SetAttribute("list", "c");
     // System.out.println(duh);
     string expecting = "<b>blort: abc</b>";
     Assert.AreEqual(expecting, duh.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:14,代码来源:TestStringTemplate.cs

示例5: testComplicatedSeparatorExpr

 public virtual void testComplicatedSeparatorExpr()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplate bold = group.DefineTemplate("bulletSeparator", "</li>$foo$<li>");
     // make separator a complicated expression with args passed to included template
     StringTemplate t = new StringTemplate(
         group, @"<ul>$name; separator=bulletSeparator(foo="" "")+""&nbsp;""$</ul>"
         );
     t.SetAttribute("name", "Ter");
     t.SetAttribute("name", "Tom");
     t.SetAttribute("name", "Mel");
     //System.out.println(t);
     string expecting = "<ul>Ter</li> <li>&nbsp;Tom</li> <li>&nbsp;Mel</ul>";
     Assert.AreEqual(expecting, t.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:15,代码来源:TestStringTemplate.cs

示例6: testChangingAttrValueTemplateApplicationToVector

 public virtual void testChangingAttrValueTemplateApplicationToVector()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplate bold = group.DefineTemplate("bold", "<b>$x$</b>");
     StringTemplate t = new StringTemplate(group, "$names:bold(x=it)$");
     t.SetAttribute("names", "Terence");
     t.SetAttribute("names", "Tom");
     string expecting = "<b>Terence</b><b>Tom</b>";
     Assert.AreEqual(expecting, t.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:10,代码来源:TestStringTemplate.cs

示例7: testChangingAttrValueRepeatedTemplateApplicationToVector

 public virtual void testChangingAttrValueRepeatedTemplateApplicationToVector()
 {
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     StringTemplate bold = group.DefineTemplate("bold", "<b>$item$</b>");
     StringTemplate italics = group.DefineTemplate("italics", "<i>$it$</i>");
     StringTemplate members = new StringTemplate(group, "$members:bold(item=it):italics(it=it)$");
     members.SetAttribute("members", "Jim");
     members.SetAttribute("members", "Mike");
     members.SetAttribute("members", "Ashar");
     string expecting = "<i><b>Jim</b></i><i><b>Mike</b></i><i><b>Ashar</b></i>";
     Assert.AreEqual(expecting, members.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:12,代码来源:TestStringTemplate.cs

示例8: testNullSingleValueInListWithTemplateApply

 public void testNullSingleValueInListWithTemplateApply()
 {
 StringTemplateGroup group = new StringTemplateGroup("test", typeof(AngleBracketTemplateLexer));
 StringTemplate t = group.DefineTemplate("t", "<data:array(); null=\"-1\", separator=\", \">");
 group.DefineTemplate("array", "<it>");
 IList data = new ArrayList();
 data.Add(null);
 t.SetAttribute("data", data);
 string expecting = "-1";
 Assert.AreEqual(expecting, t.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:11,代码来源:TestStringTemplate.cs

示例9: testApplyRepeatedAnonymousTemplateWithForeignTemplateRefToMultiValuedAttribute

 public virtual void testApplyRepeatedAnonymousTemplateWithForeignTemplateRefToMultiValuedAttribute()
 {
     // specify a template to apply to an attribute
     // Use a template group so we can specify the start/stop chars
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     group.DefineTemplate("link", @"<a href=""$url$""><b>$title$</b></a>");
     StringTemplate duh = new StringTemplate(
         group, @"start|$p:{$link(url=""/member/view?ID=""+it.ID, title=it.firstName)$ $if(it.canEdit)$canEdit$endif$}:"
         + "{$it$<br>\n}$|end"
         );
     duh.SetAttribute("p", new Connector());
     duh.SetAttribute("p", new Connector2());
     string expecting = @"start|<a href=""/member/view?ID=1""><b>Terence</b></a> <br>" + NL
         + @"<a href=""/member/view?ID=2""><b>Tom</b></a> canEdit<br>" + NL + "|end";
     Assert.AreEqual(expecting, duh.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:16,代码来源:TestStringTemplate.cs

示例10: testEmptyExprAsFirstLineGetsNoOutput

 public virtual void testEmptyExprAsFirstLineGetsNoOutput()
 {
 StringTemplateGroup group =
     new StringTemplateGroup("test");
 IStringTemplateErrorListener errors = new ErrorBuffer();
 group.ErrorListener = errors;
 group.DefineTemplate("bold", "<b>$it$</b>");
 StringTemplate t = new StringTemplate(group,
     "$users$\n" +
     "end\n");
 string expecting = "end\n";
 string result = t.ToString();
 Assert.AreEqual(expecting, result);
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:14,代码来源:TestStringTemplate.cs

示例11: testAlternatingTemplateApplication

 public virtual void testAlternatingTemplateApplication()
 {
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     StringTemplate listItem = group.DefineTemplate("listItem", "<li>$it$</li>");
     StringTemplate bold = group.DefineTemplate("bold", "<b>$it$</b>");
     StringTemplate italics = group.DefineTemplate("italics", "<i>$it$</i>");
     StringTemplate item = new StringTemplate(group, "$item:bold(),italics():listItem()$");
     item.SetAttribute("item", "Jim");
     item.SetAttribute("item", "Mike");
     item.SetAttribute("item", "Ashar");
     string expecting = "<li><b>Jim</b></li><li><i>Mike</i></li><li><b>Ashar</b></li>";
     Assert.AreEqual(expecting, item.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:13,代码来源:TestStringTemplate.cs

示例12: testTemplatePolymorphism

 public virtual void testTemplatePolymorphism()
 {
 StringTemplateGroup group = new StringTemplateGroup("super");
 StringTemplateGroup subGroup = new StringTemplateGroup("sub");
 subGroup.SuperGroup = group;
 // bold is defined in both super and sub
 // if you create an instance of page via the subgroup,
 // then bold() should evaluate to the subgroup not the super
 // even though page is defined in the super.  Just like polymorphism.
 group.DefineTemplate("bold", "<b>$it$</b>");
 group.DefineTemplate("page", "$name:bold()$");
 subGroup.DefineTemplate("bold", "<strong>$it$</strong>");
 StringTemplate st = subGroup.GetInstanceOf("page");
 st.SetAttribute("name", "Ter");
 string expecting = "<strong>Ter</strong>";
 Assert.AreEqual(expecting, st.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:17,代码来源:TestStringTemplate.cs

示例13: testLazyEvalOfSuperInApplySuperTemplateRef

 public virtual void testLazyEvalOfSuperInApplySuperTemplateRef()
 {
 StringTemplateGroup group = new StringTemplateGroup("base");
 StringTemplateGroup subGroup = new StringTemplateGroup("sub");
 subGroup.SuperGroup = group;
 group.DefineTemplate("bold", "<b>$it$</b>");
 subGroup.DefineTemplate("bold", "<strong>$it$</strong>");
 // this is the same as testApplySuperTemplateRef() test
 // 'cept notice that here the supergroup defines page
 // As long as you create the instance via the subgroup,
 // "super." will evaluate lazily (i.e., not statically
 // during template compilation) to the templates
 // getGroup().superGroup value.  If I create instance
 // of page in group not subGroup, however, I will get
 // an error as superGroup is null for group "group".
 group.DefineTemplate("page", "$name:super.bold()$");
 StringTemplate st = subGroup.GetInstanceOf("page");
 st.SetAttribute("name", "Ter");
 string error = null;
 try
 {
     st.ToString();
 }
 catch (StringTemplateException iae)
 {
     error = iae.Message;
 }
 string expectingError = "base has no super group; invalid template: super.bold";
 Assert.AreEqual(expectingError, error);
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:30,代码来源:TestStringTemplate.cs

示例14: testApplySuperTemplateRef

 public virtual void testApplySuperTemplateRef()
 {
 StringTemplateGroup group = new StringTemplateGroup("super");
 StringTemplateGroup subGroup = new StringTemplateGroup("sub");
 subGroup.SuperGroup = group;
 group.DefineTemplate("bold", "<b>$it$</b>");
 subGroup.DefineTemplate("bold", "<strong>$it$</strong>");
 subGroup.DefineTemplate("page", "$name:super.bold()$");
 StringTemplate st = subGroup.GetInstanceOf("page");
 st.SetAttribute("name", "Ter");
 string expecting = "<b>Ter</b>";
 Assert.AreEqual(expecting, st.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:13,代码来源:TestStringTemplate.cs

示例15: testSuperTemplateRef

 public virtual void testSuperTemplateRef()
 {
 // you can refer to a template defined in a super group via super.t()
 StringTemplateGroup group = new StringTemplateGroup("super");
 StringTemplateGroup subGroup = new StringTemplateGroup("sub");
 subGroup.SuperGroup = group;
 group.DefineTemplate("page", "$font()$:text");
 group.DefineTemplate("font", "Helvetica");
 subGroup.DefineTemplate("font", "$super.font()$ and Times");
 StringTemplate st = subGroup.GetInstanceOf("page");
 string expecting = "Helvetica and Times:text";
 Assert.AreEqual(expecting, st.ToString());
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:13,代码来源:TestStringTemplate.cs


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