Example #1
0
        public bool IsPredecessorOf(SourceFile origin)
        {
            if (origin.ParentComponent == null)
                return false;

            return this == origin.ParentComponent || IsPredecessorOf(origin.ParentComponent);
        }
Example #2
0
        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;
        }
Example #3
0
 internal void AddComponent(SourceFile component)
 {
     _components.Add(component);
 }
Example #4
0
 private static bool IsRivetFile(SourceFile sourceFile)
 {
     return sourceFile.Body.Contains(Constants.RivetToken);
 }