Represents a stream end event.
Inheritance: ParsingEvent, IStreamEnd
        private ParsingEvent ParseDocumentStart(bool isImplicit)
        {
            if (!isImplicit)
            {
                while (GetCurrentToken() is YamlDotNet.Core.Tokens.DocumentEnd)
                {
                    Skip();
                }
            }
            if (isImplicit && !(GetCurrentToken() is VersionDirective) && !(GetCurrentToken() is TagDirective) && !(GetCurrentToken() is YamlDotNet.Core.Tokens.DocumentStart) && !(GetCurrentToken() is YamlDotNet.Core.Tokens.StreamEnd))
            {
                TagDirectiveCollection tags = new TagDirectiveCollection();
                ProcessDirectives(tags);
                states.Push(ParserState.DocumentEnd);
                state = ParserState.BlockNode;
                return(new YamlDotNet.Core.Events.DocumentStart(null, tags, true, GetCurrentToken().Start, GetCurrentToken().End));
            }
            if (!(GetCurrentToken() is YamlDotNet.Core.Tokens.StreamEnd))
            {
                Mark start = GetCurrentToken().Start;
                TagDirectiveCollection tags2   = new TagDirectiveCollection();
                VersionDirective       version = ProcessDirectives(tags2);
                Token token = GetCurrentToken();
                if (!(token is YamlDotNet.Core.Tokens.DocumentStart))
                {
                    throw new SemanticErrorException(token.Start, token.End, "Did not find expected <document start>.");
                }
                states.Push(ParserState.DocumentEnd);
                state = ParserState.DocumentContent;
                ParsingEvent result = new YamlDotNet.Core.Events.DocumentStart(version, tags2, false, start, token.End);
                Skip();
                return(result);
            }
            state = ParserState.StreamEnd;
            ParsingEvent result2 = new YamlDotNet.Core.Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);

            if (scanner.MoveNextWithoutConsuming())
            {
                throw new InvalidOperationException("The scanner should contain no more tokens.");
            }
            return(result2);
        }
Exemple #2
0
        /// <summary>
        /// Parse the productions:
        /// implicit_document    ::= block_node DOCUMENT-END*
        ///                          *
        /// explicit_document    ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
        ///                          *************************
        /// </summary>
        private ParsingEvent ParseDocumentStart(bool isImplicit)
        {
            // Parse extra document end indicators.

            if (!isImplicit)
            {
                while (GetCurrentToken() is DocumentEnd)
                {
                    Skip();
                }
            }

            // Parse an isImplicit document.

            if (isImplicit && !(GetCurrentToken() is VersionDirective || GetCurrentToken() is TagDirective || GetCurrentToken() is DocumentStart || GetCurrentToken() is StreamEnd))
            {
                var directives = new TagDirectiveCollection();
                ProcessDirectives(directives);

                states.Push(ParserState.DocumentEnd);

                state = ParserState.BlockNode;

                return new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End);
            }

            // Parse an explicit document.

            else if (!(GetCurrentToken() is StreamEnd))
            {
                Mark start = GetCurrentToken().Start;
                var directives = new TagDirectiveCollection();
                var versionDirective = ProcessDirectives(directives);

                var current = GetCurrentToken();
                if (!(current is DocumentStart))
                {
                    throw new SemanticErrorException(current.Start, current.End, "Did not find expected <document start>.");
                }

                states.Push(ParserState.DocumentEnd);

                state = ParserState.DocumentContent;

                ParsingEvent evt = new Events.DocumentStart(versionDirective, directives, false, start, current.End);
                Skip();
                return evt;
            }

            // Parse the stream end.

            else
            {
                state = ParserState.StreamEnd;

                ParsingEvent evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
                // Do not call skip here because that would throw an exception
                if (scanner.MoveNextWithoutConsuming())
                {
                    throw new InvalidOperationException("The scanner should contain no more tokens.");
                }
                return evt;
            }
        }
Exemple #3
0
        /// <summary>
        /// Parse the productions:
        /// implicit_document    ::= block_node DOCUMENT-END*
        ///                          *
        /// explicit_document    ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
        ///                          *************************
        /// </summary>
        private ParsingEvent ParseDocumentStart(bool isImplicit)
        {
            if (currentToken is VersionDirective)
            {
                // EB22
                throw new SyntaxErrorException("While parsing a document start node, could not find document end marker before version directive.");
            }

            // Parse extra document end indicators.

            var current = GetCurrentToken();

            if (!isImplicit)
            {
                while (current is DocumentEnd)
                {
                    Skip();
                    current = GetCurrentToken();
                }
            }

            if (current == null)
            {
                throw new SyntaxErrorException("Reached the end of the stream while parsing a document start.");
            }

            if (current is Scalar && (state == ParserState.ImplicitDocumentStart || state == ParserState.DocumentStart))
            {
                isImplicit = true;
            }

            // Parse an isImplicit document.

            if (isImplicit && !(current is VersionDirective || current is TagDirective || current is DocumentStart || current is StreamEnd || current is DocumentEnd) || current is BlockMappingStart)
            {
                var directives = new TagDirectiveCollection();
                ProcessDirectives(directives);

                states.Push(ParserState.DocumentEnd);

                state = ParserState.BlockNode;

                return(new Events.DocumentStart(null, directives, true, current.Start, current.End));
            }

            // Parse an explicit document.

            else if (!(current is StreamEnd || current is DocumentEnd))
            {
                var start            = current.Start;
                var directives       = new TagDirectiveCollection();
                var versionDirective = ProcessDirectives(directives);

                current = GetCurrentToken() ?? throw new SemanticErrorException("Reached the end of the stream while parsing a document start");

                if (!(current is DocumentStart))
                {
                    throw new SemanticErrorException(current.Start, current.End, "Did not find expected <document start>.");
                }

                states.Push(ParserState.DocumentEnd);

                state = ParserState.DocumentContent;

                var end = current.End;
                Skip();
                return(new Events.DocumentStart(versionDirective, directives, false, start, end));
            }

            // Parse the stream end.

            else
            {
                if (current is DocumentEnd)
                {
                    Skip();
                }
                state = ParserState.StreamEnd;

                current = GetCurrentToken() ?? throw new SemanticErrorException("Reached the end of the stream while parsing a document start");

                var evt = new Events.StreamEnd(current.Start, current.End);
                // Do not call skip here because that would throw an exception
                if (scanner.MoveNextWithoutConsuming())
                {
                    throw new InvalidOperationException("The scanner should contain no more tokens.");
                }
                return(evt);
            }
        }
Exemple #4
0
        /// <summary>
        /// Parse the productions:
        /// implicit_document    ::= block_node DOCUMENT-END*
        ///                          *
        /// explicit_document    ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
        ///                          *************************
        /// </summary>
        private Event ParseDocumentStart(bool isImplicit)
        {
            // Parse extra document end indicators.

            if (!isImplicit)
            {
                while (GetCurrentToken() is DocumentEnd)
                {
                    Skip();
                }
            }

            // Parse an isImplicit document.

            if (isImplicit && !(GetCurrentToken() is VersionDirective || GetCurrentToken() is TagDirective || GetCurrentToken() is DocumentStart || GetCurrentToken() is StreamEnd))
            {
                TagDirectiveCollection directives = new TagDirectiveCollection();
                ProcessDirectives(directives);

                states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);

                state = ParserState.YAML_PARSE_BLOCK_NODE_STATE;

                return(new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End));
            }

            // Parse an explicit document.

            else if (!(GetCurrentToken() is StreamEnd))
            {
                Mark start = GetCurrentToken().Start;
                TagDirectiveCollection directives       = new TagDirectiveCollection();
                VersionDirective       versionDirective = ProcessDirectives(directives);

                var current = GetCurrentToken();
                if (!(current is DocumentStart))
                {
                    throw new SemanticErrorException(current.Start, current.End, "Did not find expected <document start>.");
                }

                states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);

                state = ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE;

                Event evt = new Events.DocumentStart(versionDirective, directives, false, start, current.End);
                Skip();
                return(evt);
            }

            // Parse the stream end.

            else
            {
                state = ParserState.YAML_PARSE_END_STATE;

                Event evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
                // Do not call skip here because that would throw an exception
                if (scanner.InternalMoveNext())
                {
                    throw new InvalidOperationException("The scanner should contain no more tokens.");
                }
                return(evt);
            }
        }
Exemple #5
0
        /// <summary>
        /// Parse the productions:
        /// implicit_document    ::= block_node DOCUMENT-END*
        ///                          *
        /// explicit_document    ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
        ///                          *************************
        /// </summary>
        private ParsingEvent ParseDocumentStart(bool isImplicit)
        {
            // Parse extra document end indicators.

            if (!isImplicit)
            {
                while (GetCurrentToken() is DocumentEnd)
                {
                    Skip();
                }
            }

            // Parse an isImplicit document.

            if (isImplicit && !(GetCurrentToken() is VersionDirective || GetCurrentToken() is TagDirective || GetCurrentToken() is DocumentStart || GetCurrentToken() is StreamEnd))
            {
                var directives = new TagDirectiveCollection();
                ProcessDirectives(directives);

                states.Push(ParserState.DocumentEnd);

                state = ParserState.BlockNode;

                return(new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End));
            }

            // Parse an explicit document.

            else if (!(GetCurrentToken() is StreamEnd))
            {
                Mark start            = GetCurrentToken().Start;
                var  directives       = new TagDirectiveCollection();
                var  versionDirective = ProcessDirectives(directives);

                var current = GetCurrentToken();
                if (!(current is DocumentStart))
                {
                    throw new SemanticErrorException(current.Start, current.End, "Did not find expected <document start>.");
                }

                states.Push(ParserState.DocumentEnd);

                state = ParserState.DocumentContent;

                ParsingEvent evt = new Events.DocumentStart(versionDirective, directives, false, start, current.End);
                Skip();
                return(evt);
            }

            // Parse the stream end.

            else
            {
                state = ParserState.StreamEnd;

                ParsingEvent evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
                // Do not call skip here because that would throw an exception
                if (scanner.MoveNextWithoutConsuming())
                {
                    throw new InvalidOperationException("The scanner should contain no more tokens.");
                }
                return(evt);
            }
        }
Exemple #6
0
			void IParsingEventVisitor.Visit(StreamEnd e)
			{
				throw new NotSupportedException();
			}
Exemple #7
0
        /// <summary>
        /// Parse the productions:
        /// implicit_document    ::= block_node DOCUMENT-END*
        ///                          *
        /// explicit_document    ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
        ///                          *************************
        /// </summary>
        private Event ParseDocumentStart(bool isImplicit)
        {
            // Parse extra document end indicators.

            if (!isImplicit)
            {
                while (GetCurrentToken() is DocumentEnd)
                {
                    Skip();
                }
            }

            // Parse an isImplicit document.

            if (isImplicit && !(GetCurrentToken() is VersionDirective || GetCurrentToken() is TagDirective || GetCurrentToken() is DocumentStart || GetCurrentToken() is StreamEnd))
            {
                TagDirectiveCollection directives = new TagDirectiveCollection();
                ProcessDirectives(directives);

                states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);

                state = ParserState.YAML_PARSE_BLOCK_NODE_STATE;

                return new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End);
            }

            // Parse an explicit document.

            else if (!(GetCurrentToken() is StreamEnd))
            {
                Mark start = GetCurrentToken().Start;
                TagDirectiveCollection directives = new TagDirectiveCollection();
                VersionDirective versionDirective = ProcessDirectives(directives);

                var current = GetCurrentToken();
                if (!(current is DocumentStart))
                {
                    throw new SemanticErrorException(current.Start, current.End, "Did not find expected <document start>.");
                }

                states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);

                state = ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE;

                Event evt = new Events.DocumentStart(versionDirective, directives, false, start, current.End);
                Skip();
                return evt;
            }

            // Parse the stream end.

            else
            {
                state = ParserState.YAML_PARSE_END_STATE;

                Event evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
                // Do not call skip here because that would throw an exception
                if (scanner.InternalMoveNext())
                {
                    throw new InvalidOperationException("The scanner should contain no more tokens.");
                }
                return evt;
            }
        }