Beispiel #1
0
        public static Project ParseProject(IEnumerable <string> sourceFiles, bool runInSerial)
        {
            var files        = runInSerial ? sourceFiles : sourceFiles.AsParallel();
            var languageList = new List <ILanguageParser>();

            var parsedFiles = files.Select(path =>
            {
                Report.Message("Parsing", path);

                // Parse source files.
                ILanguageParser language;
                try
                {
                    language = ParserManager.GetParserByExtension(Path.GetExtension(path));
                }
                catch (NotSupportedException e)
                {
                    Report.Error(p => p.DescriptionReasonLocation(ReportGenre.FileRead, e.Message, path), e);
                    return(null);
                }

                languageList.AddIf(p => languageList.Select(p2 => p2.Identifier).All(i => i != p.Identifier), language);
                var source = OtherUtils.ReadAllText(path);
                return(language.Parse(path, source));
            })
                              .ToList();

            var project = new Project(parsedFiles);

            new Traverser("Global post processing", languageList.SelectMany(p => p.GlobalTraverserActions).ToArray()).Go(project);
            return(project);
        }