當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。