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


C# TemplateGroup.LoadTemplateFile方法代码示例

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


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

示例1: ImportTemplates

        /** Import template files, directories, and group files.
         *  Priority is given to templates defined in the current group;
         *  this, in effect, provides inheritance. Polymorphism is in effect so
         *  that if an inherited template references template t() then we
         *  search for t() in the subgroup first.
         *
         *  Templates are loaded on-demand from import dirs.  Imported groups are
         *  loaded on-demand when searching for a template.
         *
         *  The listener of this group is passed to the import group so errors
         *  found while loading imported element are sent to listener of this group.
         */
        public virtual void ImportTemplates(IToken fileNameToken)
        {
            string fileName = fileNameToken.Text;

            if (Verbose)
                Console.WriteLine("ImportTemplates({0})", fileName);

            // do nothing upon syntax error
            if (fileName == null || fileName.Equals("<missing STRING>"))
                return;

            fileName = Utility.Strip(fileName, 1);

            //Console.WriteLine("import {0}", fileName);
            bool isGroupFile = fileName.EndsWith(GroupFileExtension);
            bool isTemplateFile = fileName.EndsWith(TemplateFileExtension);
            bool isGroupDir = !(isGroupFile || isTemplateFile);

            TemplateGroup g = null;

            // search path is: working dir, g.stg's dir, CLASSPATH
            Uri thisRoot = RootDirUri;
            Uri fileUnderRoot = null;
            //Console.WriteLine("thisRoot={0}", thisRoot);
            try
            {
                fileUnderRoot = new Uri(thisRoot + "/" + fileName);
            }
            catch (UriFormatException mfe)
            {
                ErrorManager.InternalError(null, string.Format("can't build URL for {0}/{1}", thisRoot, fileName), mfe);
                return;
            }

            if (isTemplateFile)
            {
                g = new TemplateGroup();
                g.Listener = this.Listener;
                Uri fileURL = null;
                if (File.Exists(fileUnderRoot.LocalPath))
                    fileURL = fileUnderRoot;

                if (fileURL != null)
                {
                    try
                    {
                        Stream s = File.OpenRead(fileURL.LocalPath);
                        ANTLRInputStream templateStream = new ANTLRInputStream(s);
                        templateStream.name = fileName;
                        CompiledTemplate code = g.LoadTemplateFile("/", fileName, templateStream);
                        if (code == null)
                            g = null;
                    }
                    catch (IOException ioe)
                    {
                        ErrorManager.InternalError(null, string.Format("can't read from {0}", fileURL), ioe);
                        g = null;
                    }
                }
                else
                {
                    g = null;
                }
            }
            else if (isGroupFile)
            {
                //System.out.println("look for fileUnderRoot: "+fileUnderRoot);
                if (File.Exists(fileUnderRoot.LocalPath))
                {
                    g = new TemplateGroupFile(fileUnderRoot, Encoding, delimiterStartChar, delimiterStopChar);
                    g.Listener = this.Listener;
                }
                else
                {
                    g = new TemplateGroupFile(fileName, delimiterStartChar, delimiterStopChar);
                    g.Listener = this.Listener;
                }
            }
            else if (isGroupDir)
            {
                //			System.out.println("try dir "+fileUnderRoot);
                if (Directory.Exists(fileUnderRoot.LocalPath))
                {
                    g = new TemplateGroupDirectory(fileUnderRoot, Encoding, delimiterStartChar, delimiterStopChar);
                    g.Listener = this.Listener;
                }
                else
                {
//.........这里部分代码省略.........
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:101,代码来源:TemplateGroup.cs


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