// TODO: make this happen in background then flip ptr to new list of templates/dictionaries? public virtual void LoadGroupFile(TemplateName prefix, string fileName) { string absoluteFileName = Path.Combine(fullyQualifiedRootDirName, fileName); //Console.WriteLine("load group file " + absoluteFileName); GroupParser parser = null; try { ANTLRFileStream fs = new ANTLRFileStream(absoluteFileName, encoding); GroupLexer lexer = new GroupLexer(fs); CommonTokenStream tokens = new CommonTokenStream(lexer); parser = new GroupParser(tokens); parser.group(this, prefix); } #if false catch (RecognitionException e) { if (e.Token.Type == TemplateLexer.EOF_TYPE) ErrorManager.SyntaxError(ErrorType.SyntaxError, e, "premature EOF", absoluteFileName); else ErrorManager.SyntaxError(ErrorType.SyntaxError, e, absoluteFileName); } #endif catch (Exception e) { if (ErrorManager.IsCriticalException(e)) throw; ErrorManager.IOError(null, ErrorType.CantLoadGroupFile, e, absoluteFileName); } }
public CompiledTemplate LoadTemplateFile(TemplateName prefix, string fileName) { if (prefix == null) throw new ArgumentNullException("prefix"); if (fileName == null) throw new ArgumentNullException("fileName"); if (!prefix.IsRooted) throw new ArgumentException("Expected the prefix to be a rooted name.", "prefix"); TemplateName templateName = TemplateName.Combine(prefix, new TemplateName(Path.GetFileNameWithoutExtension(fileName))); // load from disk string absoluteFileName = Path.Combine(Path.Combine(fullyQualifiedRootDirName, prefix.FullName.Substring(1)), fileName); //Console.WriteLine("load " + absoluteFileName); if (!File.Exists(absoluteFileName)) { // TODO: add tolerance check here return null; } try { if (ErrorManager.CompatibilityMode) { string template = File.ReadAllText(absoluteFileName); template = template.Trim(); DefineTemplate(prefix, new CommonToken(GroupParser.ID, templateName.Name), null, template); } else { ANTLRFileStream fs = new ANTLRFileStream(absoluteFileName, encoding); GroupLexer lexer = new GroupLexer(fs); CommonTokenStream tokens = new CommonTokenStream(lexer); GroupParser parser = new GroupParser(tokens); parser._group = this; parser.templateDef(prefix); } CompiledTemplate code; if (!templates.TryGetValue(templateName, out code)) return null; return code; } catch (Exception e) { if (ErrorManager.IsCriticalException(e)) throw; ErrorManager.IOError(null, ErrorType.CantLoadTemplateFile, e, absoluteFileName); Console.Error.WriteLine(e.StackTrace); } return null; }