Пример #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class.
		/// </summary>
		/// <param name="events">The events.</param>
		internal YamlDocument(EventReader events)
		{
			DocumentLoadingState state = new DocumentLoadingState();

			events.Expect<DocumentStart>();

			while (!events.Accept<DocumentEnd>())
			{
				Debug.Assert(RootNode == null);
				RootNode = YamlNode.ParseNode(events, state);

				if (RootNode is YamlAliasNode)
				{
					throw new YamlException();
				}
			}

			state.ResolveAliases();

#if DEBUG
			foreach (var node in AllNodes)
			{
				if (node is YamlAliasNode)
				{
					throw new InvalidOperationException("Error in alias resolution.");
				}
			}
#endif

			events.Expect<DocumentEnd>();
		}
		/// <summary>
		/// Adds the specified node to the anchor list.
		/// </summary>
		/// <param name="node">The node.</param>
		public void AddAnchor(YamlNode node)
		{
			if (node.Anchor == null)
			{
				throw new ArgumentException("The specified node does not have an anchor");
			}

			if (anchors.ContainsKey(node.Anchor))
			{
				throw new DuplicateAnchorException(node.Start, node.End, string.Format(CultureInfo.InvariantCulture, "The anchor '{0}' already exists", node.Anchor));
			}

			anchors.Add(node.Anchor, node);
		}
		/// <summary>
		/// Adds the specified node to the collection of nodes with unresolved aliases.
		/// </summary>
		/// <param name="node">
		/// The <see cref="YamlNode"/> that has unresolved aliases.
		/// </param>
		public void AddNodeWithUnresolvedAliases(YamlNode node)
		{
			nodesWithUnresolvedAliases.Add(node);
		}
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlDocument"/> class with a single scalar node.
 /// </summary>
 public YamlDocument(string rootNode)
 {
     RootNode = new YamlScalarNode(rootNode);
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YamlDocument"/> class.
 /// </summary>
 public YamlDocument(YamlNode rootNode)
 {
     RootNode = rootNode;
 }
Пример #6
0
		/// <summary>
		/// Provides a basic implementation of Object.Equals 
		/// </summary>
		protected bool Equals(YamlNode other)
		{
			// Do not use the anchor in the equality comparison because that would prevent anchored nodes from being found in dictionaries.
			return SafeEquals(Tag, other.Tag);
		}
Пример #7
0
 /// <summary>
 /// Called when this object is visiting a key-value pair.
 /// </summary>
 /// <param name="key">The left (key) <see cref="YamlNode"/> that is being visited.</param>
 /// <param name="value">The right (value) <see cref="YamlNode"/> that is being visited.</param>
 protected virtual void VisitPair(YamlNode key, YamlNode value)
 {
     key.Accept(this);
     value.Accept(this);
 }
Пример #8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class with a single scalar node.
		/// </summary>
		public YamlDocument(string rootNode)
		{
			RootNode = new YamlScalarNode(rootNode);
		}
Пример #9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class.
		/// </summary>
		public YamlDocument(YamlNode rootNode)
		{
			RootNode = rootNode;
		}
Пример #10
0
			private void VisitNode(YamlNode node)
			{
				if (string.IsNullOrEmpty(node.Anchor))
				{
					bool isDuplicate;
					if (visitedNodes.TryGetValue(node, out isDuplicate))
					{
						if (!isDuplicate)
						{
							visitedNodes[node] = true;
						}
					}
					else
					{
						visitedNodes.Add(node, false);
					}
				}
				else
				{
					existingAnchors.Add(node.Anchor);
				}
			}