private static void runOnce(Config config) { TextWriter w; if (config.ErrorFile == null) w = System.Console.Error; else w = File.CreateText(config.ErrorFile); AbstractErrorWriter writer; if (config.IsErrorXML) writer = new XMLWriter(w); else writer = new ConsoleWriter(w); writer.Outputs = config.OutputFiles; var parser = new Parser(); parser.CustomSymbols = loadCopies(config.Copies); for(int c=0; c<config.InputFiles.Count; c++) { string path = config.InputFiles[c]; try { parser.Init(path, config.Format); } catch(System.IO.IOException ex) { AddError(writer, ex.Message, path); continue; } parser.Parse(path); if (parser.Results.CodeElementsDocumentSnapshot == null) { AddError(writer, "File \""+path+"\" has syntactic error(s) preventing codegen (CodeElements).", path); continue; } writer.AddErrors(path, parser.Converter.AsDiagnostics(parser.Results.CodeElementsDocumentSnapshot.ParserDiagnostics)); // no need to add errors from parser.CodeElementsSnapshot.CodeElements // as they are on parser.CodeElementsSnapshot.CodeElements which are added below if (parser.Results.ProgramClassDocumentSnapshot == null) { AddError(writer, "File \""+path+"\" has semantic error(s) preventing codegen (ProgramClass).", path); continue; } int errors = 0; errors += new List<Compiler.Diagnostics.Diagnostic>(parser.Results.CodeElementsDocumentSnapshot.ParserDiagnostics).Count; errors += parser.Results.ProgramClassDocumentSnapshot.Diagnostics.Count; writer.AddErrors(path, parser.Converter.AsDiagnostics(parser.Results.ProgramClassDocumentSnapshot.Diagnostics)); foreach(var e in parser.Results.CodeElementsDocumentSnapshot.CodeElements) { if (e.Diagnostics.Count < 1) continue; errors += e.Diagnostics.Count; writer.AddErrors(path, parser.Converter.GetDiagnostics(e)); } if (config.Codegen && (errors == 0 || !config.Safe)) { var skeletons = TypeCobol.Codegen.Config.Config.Parse(config.skeletonPath); var codegen = new TypeCobol.Codegen.Generator(new StreamWriter(config.OutputFiles[c]), parser.Results.TokensLines, skeletons); var program = parser.Results.ProgramClassDocumentSnapshot.Program; codegen.Generate(program.SyntaxTree.Root, program.SymbolTable, ColumnsLayout.CobolReferenceFormat); } } writer.Write(); writer.Flush(); }