• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# StringTemplate.TemplateGroup类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TemplateGroup类属于Antlr4.StringTemplate命名空间,在下文中一共展示了TemplateGroup类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: StringTemplateViewEngine

 /// <summary>
 /// Creates a new instance of the StringTemplateViewEngine
 /// </summary>
 /// <param name="viewPath">The physical path to the root views directory</param>
 public StringTemplateViewEngine(string viewPath)
 {
    Group = new TemplateGroupDirectory(viewPath, '$', '$')
               {
                  Listener = new Log4NetTemplateErrorListener()
               };
 }
开发者ID:ericklombardo,项目名称:Nuaguil.Net,代码行数:11,代码来源:StringTemplateViewEngine.cs


示例2: LoadPrecRuleTemplates

        public virtual void LoadPrecRuleTemplates()
        {
            string templateGroupFile = Path.Combine("Tool", "Templates", "LeftRecursiveRules.stg");
            recRuleTemplates = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    templateGroupFile),
                Encoding.UTF8);
            if (!recRuleTemplates.IsDefined("recRule"))
            {
                tool.errMgr.ToolError(ErrorType.MISSING_CODE_GEN_TEMPLATES, "LeftRecursiveRules");
            }

            // use codegen to get correct language templates; that's it though
            CodeGenerator gen = new CodeGenerator(tool, null, language);
            TemplateGroup templates = gen.GetTemplates();
            if (templates == null)
            {
                // this class will still operate using Java templates
                templates = new CodeGenerator(tool, null, "Java").GetTemplates();
                Debug.Assert(templates != null);
            }

            codegenTemplates = templates;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:25,代码来源:LeftRecursiveRuleAnalyzer.cs


示例3: GetTemplates

        public virtual TemplateGroup GetTemplates()
        {
            if (templates == null)
            {
                templates = LoadTemplates();
            }

            return templates;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:9,代码来源:Target.cs


示例4: 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


示例5: 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


示例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: 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


示例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: 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


示例11: 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


示例12: 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


示例13: ReplacePropertyTokensInGroups

        public static string ReplacePropertyTokensInGroups(IEnumerable collection, string groupTemplate)
        {
            StringBuilder resultBuilder = new StringBuilder();

            foreach (var listItem in collection)
            {
                //We need new template for every collection item so that sub collection items like registrants are cleaned up
                TemplateGroup eventGroup = new TemplateGroup(TextTemplateUtils.DefaultTokenStartDelimiter, TextTemplateUtils.DefaultTokenEndDelimiter);
                eventGroup.RegisterRenderer(typeof(string), new StringRenderer());
                Template eventTemplate = new Template(eventGroup, groupTemplate);

                AddPropertiesToTemplate(listItem, eventTemplate);
                resultBuilder.Append(eventTemplate.Render(CultureInfo.InvariantCulture));
            }

            return resultBuilder.ToString();
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:17,代码来源:TextTemplateUtils.cs


示例14: GetTemplateGroup

        protected TemplateGroup GetTemplateGroup(List<string> templateNames)
        {
            if (tg == null)
            {
                // combile the header and all .st files and load everything into a TemplateGroup
                tg = new TemplateGroup();
                foreach (var templateName in templateNames)
                {
                    tg.ImportTemplates(GetTemplateGroupFromResource(templateName));
                }
                foreach (var type in attributeRenderers.Keys)
                {
                    var renderer = attributeRenderers[type];
                    tg.RegisterRenderer(type, renderer);
                }
            }

            return tg;
        }
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:19,代码来源:TemplateLoader.cs


示例15: 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


示例16: 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


示例17: TestIndirectTemplateIncludeViaTemplate

 public void TestIndirectTemplateIncludeViaTemplate()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("foo", "bar");
     group.DefineTemplate("tname", "foo");
     string template = "<(tname())()>";
     group.DefineTemplate("test", template, new string[] { "name" });
     Template st = group.GetInstanceOf("test");
     string expected = "bar";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:TestIndirectionAndEarlyEval.cs


示例18: TestSeparatorWithNullFirstValueAndNullOption

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


示例19: TestIndirectTemplateIncludeWithArgs

 public void TestIndirectTemplateIncludeWithArgs()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("foo", "<x><y>", new string[] { "x", "y" });
     string template = "<(name)({1},{2})>";
     group.DefineTemplate("test", template, new string[] { "name" });
     Template st = group.GetInstanceOf("test");
     st.Add("name", "foo");
     string expected = "12";
     string result = st.Render();
     Assert.AreEqual(expected, result);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:TestIndirectionAndEarlyEval.cs


示例20: TestParallelMapThenMap

 public void TestParallelMapThenMap()
 {
     TemplateGroup group = new TemplateGroup();
     group.DefineTemplate("bold", "[<x>]", new string[] { "x" });
     group.DefineTemplate("test", "hi <names,phones:{n,p | <n>:<p>;}:bold()>", 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,代码行数:16,代码来源:TestCoreBasics.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# StringTemplate.TemplateGroupFile类代码示例发布时间:2022-05-24
下一篇:
C# Atn.ATNState类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap