public override void Load() { if (alreadyLoaded) return; alreadyLoaded = true; GroupParser parser = null; try { ANTLRStringStream fs = new ANTLRStringStream(text); fs.name = sourceName; GroupLexer lexer = new GroupLexer(fs); CommonTokenStream tokens = new CommonTokenStream(lexer); parser = new GroupParser(tokens); // no prefix since this group file is the entire group, nothing lives // beneath it. parser.group(this, "/"); } catch (Exception e) { ErrorManager.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, FileName); } }
/** Load a group file with full path fileName; it's relative to root by prefix. */ public virtual void LoadGroupFile(string prefix, string fileName) { if (Verbose) { Console.Out.WriteLine("{0}.LoadGroupFile(prefix={1}, fileName={2})", GetType().FullName, prefix, fileName); } GroupParser parser = null; try { Uri f = new Uri(fileName); ANTLRReaderStream fs = new ANTLRReaderStream(new System.IO.StreamReader(f.LocalPath, Encoding)); var timer = System.Diagnostics.Stopwatch.StartNew(); string cachePath = Path.Combine(Path.GetTempPath(), "ST4TemplateCache"); if (EnableCache && TryLoadGroupFromCache(cachePath, prefix, fileName)) { System.Diagnostics.Debug.WriteLine(string.Format("Successfully loaded the group from cache {0} in {1}ms.", Name, timer.ElapsedMilliseconds)); } else { GroupLexer lexer = new GroupLexer(fs); fs.name = fileName; CommonTokenStream tokens = new CommonTokenStream(lexer); parser = new GroupParser(tokens); parser.group(this, prefix); System.Diagnostics.Debug.WriteLine(string.Format("Successfully loaded the group {0} in {1}ms.", Name, timer.ElapsedMilliseconds)); if (EnableCache) CacheCompiledGroup(cachePath, prefix, fileName, File.GetLastWriteTimeUtc(f.LocalPath)); } } catch (Exception e) { e.PreserveStackTrace(); if (e.IsCritical()) throw; ErrorManager.IOError(null, ErrorType.CANT_LOAD_GROUP_FILE, e, fileName); } }