예제 #1
0
        /// <summary>
        /// Parses the node represented by the next event in <paramref name="events" />.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="state">The state.</param>
        /// <returns>Returns the node that has been parsed.</returns>
        static internal YamlNode ParseNode(EventReader events, DocumentLoadingState state)
        {
            if (events.Accept <Scalar>())
            {
                return(new YamlScalarNode(events, state));
            }

            if (events.Accept <SequenceStart>())
            {
                return(new YamlSequenceNode(events, state));
            }

            if (events.Accept <MappingStart>())
            {
                return(new YamlMappingNode(events, state));
            }

            if (events.Accept <AnchorAlias>())
            {
                AnchorAlias alias = events.Expect <AnchorAlias>();
                return(state.GetNode(alias.Value, false, alias.Start, alias.End) ?? new YamlAliasNode(alias.Value));
            }

            throw new ArgumentException("The current event is of an unsupported type.", "events");
        }
예제 #2
0
 /// <summary>
 /// Resolves the aliases that could not be resolved when the node was created.
 /// </summary>
 /// <param name="state">The state of the document.</param>
 internal override void ResolveAliases(DocumentLoadingState state)
 {
     for (int i = 0; i < children.Count; ++i)
     {
         if (children[i] is YamlAliasNode)
         {
             children[i] = state.GetNode(children[i].Anchor, true, children[i].Start, children[i].End);
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Resolves the aliases that could not be resolved when the node was created.
        /// </summary>
        /// <param name="state">The state of the document.</param>
        internal override void ResolveAliases(DocumentLoadingState state)
        {
            Dictionary <YamlNode, YamlNode> keysToUpdate   = null;
            Dictionary <YamlNode, YamlNode> valuesToUpdate = null;

            foreach (var entry in children)
            {
                if (entry.Key is YamlAliasNode)
                {
                    if (keysToUpdate == null)
                    {
                        keysToUpdate = new Dictionary <YamlNode, YamlNode>();
                    }
                    keysToUpdate.Add(entry.Key, state.GetNode(entry.Key.Anchor, true, entry.Key.Start, entry.Key.End));
                }
                if (entry.Value is YamlAliasNode)
                {
                    if (valuesToUpdate == null)
                    {
                        valuesToUpdate = new Dictionary <YamlNode, YamlNode>();
                    }
                    valuesToUpdate.Add(entry.Key, state.GetNode(entry.Value.Anchor, true, entry.Value.Start, entry.Value.End));
                }
            }
            if (valuesToUpdate != null)
            {
                foreach (var entry in valuesToUpdate)
                {
                    children[entry.Key] = entry.Value;
                }
            }
            if (keysToUpdate != null)
            {
                foreach (var entry in keysToUpdate)
                {
                    YamlNode value = children[entry.Key];
                    children.Remove(entry.Key);
                    children.Add(entry.Value, value);
                }
            }
        }
예제 #4
0
		/// <summary>
		/// Parses the node represented by the next event in <paramref name="events" />.
		/// </summary>
		/// <param name="events">The events.</param>
		/// <param name="state">The state.</param>
		/// <returns>Returns the node that has been parsed.</returns>
		static internal YamlNode ParseNode(EventReader events, DocumentLoadingState state)
		{
			if (events.Accept<Scalar>())
			{
				return new YamlScalarNode(events, state);
			}

			if (events.Accept<SequenceStart>())
			{
				return new YamlSequenceNode(events, state);
			}

			if (events.Accept<MappingStart>())
			{
				return new YamlMappingNode(events, state);
			}

			if (events.Accept<AnchorAlias>())
			{
				AnchorAlias alias = events.Expect<AnchorAlias>();
				return state.GetNode(alias.Value, false, alias.Start, alias.End) ?? new YamlAliasNode(alias.Value);
			}

			throw new ArgumentException("The current event is of an unsupported type.", "events");
		}