public override IEnumerable<ITextNode> Parse(SnapshotParseContext snapshotParseContext, ITextNode textNode)
        {
            var key = textNode.GetAttributeValue("Key");
            if (string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(textNode.Value))
            {
                key = textNode.Value;
            }

            if (string.IsNullOrEmpty(key))
            {
                key = string.Empty;
            }

            List<ITextNode> textNodes;
            return snapshotParseContext.PlaceholderTextNodes.TryGetValue(key, out textNodes) ? textNodes : Enumerable.Empty<ITextNode>();
        }
        public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile)
        {
            var lines = sourceFile.ReadAsLines(snapshotParseContext.Tokens);

            var sb = new StringBuilder();

            foreach (var line in lines)
            {
                if (line.StartsWith("---"))
                {
                    sb.AppendLine("- Item:");
                }
                else
                {
                    sb.AppendLine("  " + line);
                }
            }

            return(Factory.UnicornTextSnapshot(sourceFile, sb.ToString()));
        }
 public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) => Factory.SerializationTextSnapshot(sourceFile);
        public override IEnumerable<ITextNode> Parse(SnapshotParseContext snapshotParseContext, ITextNode textNode)
        {
            var mutableTextNode = textNode as IMutableTextNode;
            if (mutableTextNode == null)
            {
                throw new InvalidOperationException("Text node cannot be modified");
            }

            var textNodes = new List<ITextNode>();

            if (!textNode.Attributes.Any() && textNode.ChildNodes.Any())
            {
                foreach (var childNode in textNode.ChildNodes)
                {
                    var collection = Parse(snapshotParseContext, childNode);
                    if (collection != null)
                    {
                        textNodes.AddRange(collection);
                    }
                }

                return textNodes;
            }

            var fileName = textNode.GetAttributeValue("File");
            if (string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(textNode.Value))
            {
                fileName = textNode.Value;
            }

            if (string.IsNullOrEmpty(fileName))
            {
                throw new InvalidOperationException("'File' attribute expected");
            }

            // todo: enable this check
            /*
            if (!string.Equals(Path.GetExtension(fileName), Path.GetExtension(textNode.Snapshot.SourceFile.AbsoluteFileName), StringComparison.OrdinalIgnoreCase))
            {
                throw new InvalidOperationException("Include file has a different format (Json/Xml/Yaml)");
            }
            */

            var placeholderTextNodes = new Dictionary<string, List<ITextNode>>(snapshotParseContext.PlaceholderTextNodes);

            var placeholdersTextNode = textNode.GetSnapshotLanguageSpecificChildNode("Placeholders");
            if (placeholdersTextNode != null)
            {
                foreach (var childNode in placeholdersTextNode.ChildNodes)
                {
                    var placeholderKey = childNode.GetAttributeValue("Key");
                    placeholderTextNodes[placeholderKey] = childNode.ChildNodes.ToList();
                }
            }

            mutableTextNode.ChildNodeCollection.Clear();

            var tokens = new Dictionary<string, string>(snapshotParseContext.Tokens).AddRange(textNode.Attributes.ToDictionary(a => a.Key, a => a.Value));
            var context = new SnapshotParseContext(snapshotParseContext.SnapshotService, tokens, placeholderTextNodes);

            textNodes.Add(snapshotParseContext.SnapshotService.LoadIncludeFile(context, textNode.Snapshot, fileName));

            return textNodes;
        }
 public abstract ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile);
예제 #6
0
        public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile)
        {
            var contents = sourceFile.ReadAsText(snapshotParseContext.Tokens);

            return(Factory.JsonTextSnapshot(sourceFile, contents));
        }
 public abstract IEnumerable<ITextNode> Parse(SnapshotParseContext snapshotParseContext, ITextNode textNode);
예제 #8
0
        public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile)
        {
            var contents = sourceFile.ReadAsText(snapshotParseContext.Tokens);

            return(Factory.XmlTextSnapshot(sourceFile, contents, SchemaNamespace, SchemaFileName));
        }
예제 #9
0
 public abstract ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile);