ParseNode() static private method

Parses the node represented by the next event in parser.
static private ParseNode ( IParser parser, DocumentLoadingState state ) : YamlNode
parser IParser
state DocumentLoadingState
return YamlNode
Beispiel #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>();
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlDocument"/> class.
        /// </summary>
#pragma warning disable CS8618 // Non-nullable field is uninitialized. There is a guard that throws an exception if this happens (upstream bug: https://github.com/dotnet/roslyn/issues/44046).
        internal YamlDocument(IParser parser)
#pragma warning restore CS8618 // Non-nullable field is uninitialized.
        {
            var state = new DocumentLoadingState();

            parser.Consume <DocumentStart>();

            while (!parser.TryConsume <DocumentEnd>(out var _))
            {
                Debug.Assert(RootNode == null);
                RootNode = YamlNode.ParseNode(parser, state);

                if (RootNode is YamlAliasNode)
                {
                    throw new YamlException("A document cannot contain only an alias");
                }
            }

            state.ResolveAliases();

            if (RootNode == null)
            {
                // This should not happen unless the parser has a bug
                throw new ArgumentException("Atempted to parse an empty document");
            }
        }
Beispiel #3
0
        internal YamlDocument(EventReader events)
        {
            DocumentLoadingState state = new DocumentLoadingState();

            events.Expect <DocumentStart>();
            while (!events.Accept <DocumentEnd>())
            {
                this.RootNode = YamlNode.ParseNode(events, state);
                if (this.RootNode is YamlAliasNode)
                {
                    throw new YamlException();
                }
            }
            state.ResolveAliases();
            events.Expect <DocumentEnd>();
        }
Beispiel #4
0
        internal YamlDocument(IParser parser)
        {
            DocumentLoadingState documentLoadingState = new DocumentLoadingState();

            parser.Expect <DocumentStart>();
            while (!parser.Accept <DocumentEnd>())
            {
                Debug.Assert(RootNode == null);
                RootNode = YamlNode.ParseNode(parser, documentLoadingState);
                if (RootNode is YamlAliasNode)
                {
                    throw new YamlException();
                }
            }
            documentLoadingState.ResolveAliases();
            parser.Expect <DocumentEnd>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="YamlDocument"/> class.
        /// </summary>
        internal YamlDocument(IParser parser)
        {
            var state = new DocumentLoadingState();

            parser.Consume <DocumentStart>();

            while (!parser.TryConsume <DocumentEnd>(out var _))
            {
                Debug.Assert(RootNode == null);
                RootNode = YamlNode.ParseNode(parser, state);

                if (RootNode is YamlAliasNode)
                {
                    throw new YamlException("A document cannot contain only an alias");
                }
            }

            state.ResolveAliases();

            // Throw should not happen unless the parser has a bug
            RootNode = RootNode ?? throw new ArgumentException("Atempted to parse an empty document");
        }