本文整理汇总了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
{
//.........这里部分代码省略.........