public SourceFiles ParseSourceFiles(IEnumerable<SourceFile> sourceFiles, ParserOptions parserOptions) { if (sourceFiles == null) throw new ArgumentNullException("sourceFiles"); if (sourceFiles.Count(sourceFile => sourceFile.Body == null) > 0) throw new InvalidOperationException(ExceptionMessages.InvalidOperationException__UnableToCombine_SourceFileContainsNullBody); if (sourceFiles.Count(sourceFile => sourceFile.Identity == null) > 0) throw new InvalidOperationException(ExceptionMessages.InvalidOperationException__UnableToCombine_SourceFileContainsNullFileName); if (sourceFiles.Count(sourceFile => sourceFile.Identity.Trim().Length == 0) > 0) throw new InvalidOperationException(ExceptionMessages.InvalidOperationException__UnableToCombine_SourceFileContainsEmptyFileName); return ParseSourceFilesInternal(sourceFiles, parserOptions); }
private SourceFile ParseSourceFile(SourceFile origin, IEnumerable<SourceFile> sourceFiles, ParserOptions parserOptions) { var outputFile = new SourceFile(origin.Identity, string.Empty); var includeReferences = ReferenceLocator.FindReferences(origin.Body); foreach (var includeReference in includeReferences) { var include = ReferenceResolver.ResolveReference(origin.BasePath, includeReference, sourceFiles); if (include != null) { if (include.IsPredecessorOf(origin)) throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidOperationException__UnableToCombine_CircularReferenceFound, include.Identity)); if (IsRivetFile(include)) { include.ParentComponent = origin; var nestedSourceFile = ParseSourceFile(include, sourceFiles, parserOptions); outputFile.Body += nestedSourceFile.Body; foreach (var component in nestedSourceFile.Components) outputFile.AddComponent(component); } else { if (include.Body.Trim().Length == 0) throw new InvalidOperationException(ExceptionMessages.InvalidOperationException__UnableToCombine_SourceFileContainsEmptyBody); outputFile.Body += _preProcessors.Aggregate(include.Body, (current, preProcessor) => preProcessor.Process(current, parserOptions)); outputFile.AddComponent(include); } } else throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidOperationException__UnableToCombine_ReferenceNotFound, includeReference, origin.Identity)); } return outputFile; }
private SourceFiles ParseSourceFilesInternal(IEnumerable<SourceFile> sourceFiles, ParserOptions parserOptions) { IEnumerable<SourceFile> rivetFiles = sourceFiles.Where(IsRivetFile); var outputFiles = new SourceFiles(); foreach (var markedFile in rivetFiles) { var outputFile = ParseSourceFile(markedFile, sourceFiles, parserOptions); outputFiles.Add(outputFile); } return outputFiles; }