private static void GetOptions(string path, Options options) { var parserExceptions = new ListenerAndAggregater <OptionReaderException>(); var projectFileReader = new OptionsReader <Options>(5, "Project file") { ErrorListener = parserExceptions }; var projFileSource = OtherUtils.ReadAllText(path); PathUtils.RunInDirectory( Path.GetDirectoryName(path), () => projectFileReader.Parse(options, path, projFileSource)); var ws = parserExceptions.Warnings; var es = parserExceptions.Errors; // Report any errors to the user. Action <ConsolePublisher, OptionReaderException> action = (p, e) => p.DescriptionReasonLocation(ReportGenre.ProjectFile, e.Message, StringUtils.LocationString(e.StartLine, e.EndLine, Path.GetFullPath(path))); if (ws.Any()) { Report.Warnings(action, ws); } if (es.Any()) { Report.Errors(action, es); } }
public ISourceFile Parse(string sourceName, string source) { // Parse and post process AST. var pListener = new ListenerAndAggregater <ParserException>(); var sourceFile = new Parser(this.Language, this.BlockParsers) { ErrorListener = pListener } .Parse(sourceName, source, this.Preprocessor); // Report warnings for both warnings and errors frot he parser. var pErrors = pListener.Warnings.Concat(pListener.Errors).ToList(); if (pErrors.Any()) { Report.Warnings((pub, e) => CreatePActionPublisher(sourceName, pub, e), pErrors.OrderBy(err => err.StartLine)); } var tListener = new ListenerAndAggregater <TraverserException>(); foreach (var t in this.Traversers) { t.ErrorListener = tListener; t.Go(sourceFile); } // Report warnings for both warnings and errors from the traversers. var tErrors = tListener.Warnings.Concat(tListener.Errors).ToList(); if (tErrors.Any()) { Report.Warnings((pub, e) => CreateTActionPublisher(sourceName, e, pub), tErrors.OrderBy(err => (err.Cause as IHasLines ?? Traversal.AncestorOfType <IHasLines>(err.Cause as IContained))?.Lines.FirstOrDefault().Number)); } return(sourceFile); }