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


C# TemplateGroupFile.RegisterRenderer方法代码示例

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


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

示例1: TestInstanceofRenderer

 public void TestInstanceofRenderer()
 {
     string templates =
             "numberThing(x,y,z) ::= \"numbers: <x>, <y>; <z>\"\n";
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     group.RegisterRenderer(typeof(int), new NumberRenderer());
     group.RegisterRenderer(typeof(double), new NumberRenderer());
     Template st = group.GetInstanceOf("numberThing");
     st.Add("x", -2100);
     st.Add("y", 3.14159);
     st.Add("z", "hi");
     string expecting = "numbers: -2100, 3.14159; hi";
     string result = st.Render();
     Assert.AreEqual(expecting, result);
 }
开发者ID:antlr,项目名称:antlrcs,代码行数:16,代码来源:TestRenderers.cs

示例2: TestLocaleWithNumberRenderer

        public void TestLocaleWithNumberRenderer()
        {
            //string templates = "foo(x,y) ::= << <x; format=\"%,d\"> <y; format=\"%,2.3f\"> >>\n";
            string templates = "foo(x,y) ::= << <x; format=\"{0:#,#}\"> <y; format=\"{0:0.000}\"> >>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.RegisterRenderer(typeof(int), new NumberRenderer());
            group.RegisterRenderer(typeof(double), new NumberRenderer());
            Template st = group.GetInstanceOf("foo");
            st.Add("x", -2100);
            st.Add("y", 3.14159);
            // Polish uses ' ' (ASCII 160) for ',' and ',' for '.'
            string expecting = " -2 100 3,142 "; // Ê
            string result = st.Render(new CultureInfo("pl"));
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:17,代码来源:TestRenderers.cs

示例3: LoadTemplates

        protected virtual TemplateGroup LoadTemplates()
        {
            TemplateGroup result = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    Path.Combine(CodeGenerator.TEMPLATE_ROOT, GetLanguage(), GetLanguage() + TemplateGroup.GroupFileExtension)),
                Encoding.UTF8);
            result.RegisterRenderer(typeof(int), new NumberRenderer());
            result.RegisterRenderer(typeof(string), new StringRenderer());
            result.Listener = new ErrorListener(this);

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

示例4: TestNumberRendererWithPrintfFormat

        public void TestNumberRendererWithPrintfFormat()
        {
            //string templates = "foo(x,y) ::= << <x; format=\"%d\"> <y; format=\"%2.3f\"> >>\n";
            string templates = "foo(x,y) ::= << <x; format=\"{0}\"> <y; format=\"{0:0.000}\"> >>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.RegisterRenderer(typeof(int), new NumberRenderer());
            group.RegisterRenderer(typeof(double), new NumberRenderer());
            Template st = group.GetInstanceOf("foo");
            st.Add("x", -2100);
            st.Add("y", 3.14159);
            string expecting = " -2100 3.142 ";
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:16,代码来源:TestRenderers.cs

示例5: TestStringRendererWithPrintfFormat

        public void TestStringRendererWithPrintfFormat()
        {
            string templates =
                    "foo(x) ::= << <x; format=\"{0,6}\"> >>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.RegisterRenderer(typeof(string), new StringRenderer());
            Template st = group.GetInstanceOf("foo");
            st.Add("x", "hi");
            string expecting = "     hi ";
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:14,代码来源:TestRenderers.cs

示例6: TestStringRendererWithTemplateInclude_cap

        public void TestStringRendererWithTemplateInclude_cap()
        {
            // must toString the t() ref before applying format
            string templates =
                    "foo(x) ::= << <(t()); format=\"cap\"> >>\n" +
                    "t() ::= <<ack>>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            //Interpreter.trace = true;
            group.RegisterRenderer(typeof(string), new StringRenderer());
            Template st = group.GetInstanceOf("foo");
            st.Add("x", "hi");
            string expecting = " Ack ";
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:17,代码来源:TestRenderers.cs

示例7: TestStringRendererWithFormat_cap_emptyValue

        public void TestStringRendererWithFormat_cap_emptyValue()
        {
            string templates =
                    "foo(x) ::= << <x; format=\"cap\"> >>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.RegisterRenderer(typeof(string), new StringRenderer());
            Template st = group.GetInstanceOf("foo");
            st.Add("x", "");
            string expecting = " ";//FIXME: why not two spaces?
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:14,代码来源:TestRenderers.cs

示例8: TestStringRendererWithFormat_xml_encode

        public void TestStringRendererWithFormat_xml_encode()
        {
            string templates =
                    "foo(x) ::= << <x; format=\"xml-encode\"> >>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.RegisterRenderer(typeof(string), new StringRenderer());
            Template st = group.GetInstanceOf("foo");
            st.Add("x", "a<b> &\t\b");
            string expecting = " a&lt;b&gt; &amp;\t\b ";
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:14,代码来源:TestRenderers.cs

示例9: TestRendererWithPredefinedFormat4

        public void TestRendererWithPredefinedFormat4()
        {
            string templates =
                    "dateThing(created) ::= << time: <created; format=\"time:medium\"> >>\n";

            writeFile(tmpdir, "t.stg", templates);
            TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
            group.RegisterRenderer(typeof(DateTime), new DateRenderer());
            group.RegisterRenderer(typeof(DateTimeOffset), new DateRenderer());
            Template st = group.GetInstanceOf("dateThing");
            st.Add("created", new DateTime(2005, 7, 5));
            string expecting = " time: 12:00:00 AM ";
            string result = st.Render();
            Assert.AreEqual(expecting, result);
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:15,代码来源:TestRenderers.cs

示例10: TestRendererForGroup

 public void TestRendererForGroup()
 {
     string templates =
             "dateThing(created) ::= \"datetime: <created>\"\n";
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     group.RegisterRenderer(typeof(DateTime), new DateRenderer());
     group.RegisterRenderer(typeof(DateTimeOffset), new DateRenderer());
     Template st = group.GetInstanceOf("dateThing");
     st.Add("created", new DateTime(2005, 7, 5));
     string expecting = "datetime: 7/5/2005 12:00 AM";
     string result = st.Render();
     Assert.AreEqual(expecting, result);
 }
开发者ID:antlr,项目名称:antlrcs,代码行数:14,代码来源:TestRenderers.cs

示例11: DT2STG

        public static int DT2STG(DataTable table, String stgFileName, String outFileName, String optFileName)
        {
            //tidy up input parameters
            stgFileName = stgFileName.Trim(); // StringTemplateGroup file
            outFileName = outFileName.Trim(); // Output file
            optFileName = optFileName.Trim(); // Options file (new 20/10/11)

            //Fail if stgFileName not passed in
            if (stgFileName == String.Empty)
                throw new ArgumentException("template file name required", "stgFileName");
            //Fail if outFileName not passed in
            if (outFileName == String.Empty)
                throw new ArgumentException("output file name required", "outFileName");

            // Get options - these will be passed to HEADER, RECORD and FOOTER templates
            // Note - Options file is optional - may not be present
            IDictionary<string, object> options = new Dictionary<string, object>();
            if (optFileName != String.Empty)
            {
                DataTable dtOptions = Delimited2DT(optFileName, true);
                if (dtOptions.Rows.Count > 0)
                {
                    foreach (DataColumn dc in dtOptions.Columns)
                    {
                        String s = dtOptions.Rows[0][dc].ToString();
                        // Ensure any leading and trailing double quotes are removed..
                        s = trimQuotes(s);
                        // Add cleaned value to the array (if not blank)
                        if (s != "")
                        {
                            options[dc.ColumnName.Trim()] = s;
                        }
                    }
                }
            }

            //Get full path to the STG file, if not already passed in
            String path = System.IO.Path.GetDirectoryName(stgFileName);
            if (path == "")
                stgFileName = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), stgFileName);

            //Revised for Antlr4...Read the template group from the file, define default delimiters
            TemplateGroupFile stg = new TemplateGroupFile(stgFileName,'$','$');

            //Register renderer for performing Url/Xml Encoding
            stg.RegisterRenderer(typeof(String), new BasicFormatRenderer());

            //System.Collections.ArrayList records = new System.Collections.ArrayList();

            //Write the results to the output file
            int rowCount = 0;
            System.IO.StreamWriter sw = null;
            try
            {
                sw = new System.IO.StreamWriter(outFileName, false);

                // If the HEADER template is present, call it and write result to output file
                if (stg.IsDefined("HEADER"))
                {
                    Template stHeader = stg.GetInstanceOf("HEADER");
                    stHeader.Add("options", options);
                    sw.WriteLine(stHeader.Render());
                }

                foreach (DataRow dr in table.Rows)
                {
                    IDictionary<string, object> record = new Dictionary<string, object>();
                    foreach (DataColumn dc in table.Columns)
                    {
                        String s = dr[dc].ToString();
                        // Ensure any leading and trailing double quotes are removed..
                        s = trimQuotes(s);
                        // Add cleaned value to the array (if not blank)
                        if (s != "")
                        {
                            record[dc.ColumnName.Trim()] = s;
                        }
                    }
                    // If the RECORD template is present, call it and write result to output file
                    if (stg.IsDefined("RECORD"))
                    {
                        Template stRecord = stg.GetInstanceOf("RECORD");
                        stRecord.Add("data", record);
                        stRecord.Add("options", options);
                        sw.WriteLine(stRecord.Render());
                    }

                    //records.Add(record);
                    rowCount++;
                }

                // If the FOOTER template is present, call it and write result to output file
                if (stg.IsDefined("FOOTER"))
                {
                    Template stFooter = stg.GetInstanceOf("FOOTER");
                    stFooter.Add("options", options);
                    sw.WriteLine(stFooter.Render());
                }
            }
            catch (Exception ex)
//.........这里部分代码省略.........
开发者ID:cbinding,项目名称:stellar,代码行数:101,代码来源:API.cs

示例12: TestRendererWithFormat

 public void TestRendererWithFormat()
 {
     string templates =
             "dateThing(created) ::= << date: <created; format=\"yyyy.MM.dd\"> >>\n";
     writeFile(tmpdir, "t.stg", templates);
     TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg"));
     group.RegisterRenderer(typeof(DateTime), new DateRenderer());
     group.RegisterRenderer(typeof(DateTimeOffset), new DateRenderer());
     Template st = group.GetInstanceOf("dateThing");
     st.Add("created", new DateTime(2005, 07, 05));
     string expecting = " date: 2005.07.05 ";
     string result = st.Render();
     Assert.AreEqual(expecting, result);
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:14,代码来源:TestRenderers.cs

示例13: LoadTemplates

        protected override TemplateGroup LoadTemplates()
        {
            // override the superclass behavior to put all C# templates in the same folder
            TemplateGroup result = new TemplateGroupFile(
                Path.Combine(
                    Path.GetDirectoryName(typeof(AntlrTool).GetTypeInfo().Assembly.Location),
                    Path.Combine(CodeGenerator.TEMPLATE_ROOT, "CSharp", GetLanguage() + TemplateGroup.GroupFileExtension)),
                Encoding.UTF8);
            result.RegisterRenderer(typeof(int), new NumberRenderer());
            result.RegisterRenderer(typeof(string), new StringRenderer());
            result.Listener = new ErrorListener(this);

            return result;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:14,代码来源:CSharpTarget.cs


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