YamlDotNet.Core.Scanner.ScanDirective C# (CSharp) Method

ScanDirective() private method

Scan a YAML-DIRECTIVE or TAG-DIRECTIVE token. Scope: %YAML 1.1 # a comment \n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %TAG !yaml! tag:yaml.org,2002: \n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
private ScanDirective ( ) : Token
return YamlDotNet.Core.Tokens.Token
        private Token ScanDirective()
        {
            // Eat '%'.

            var start = cursor.Mark();

            Skip();

            // Scan the directive name.

            var name = ScanDirectiveName(start);

            // Is it a YAML directive?

            Token directive;
            switch (name)
            {
                case "YAML":
                    directive = ScanVersionDirectiveValue(start);
                    break;

                case "TAG":
                    directive = ScanTagDirectiveValue(start);
                    break;

                default:
                    throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, find uknown directive name.");
            }

            // Eat the rest of the line including any comments.

            while (analyzer.IsWhite())
            {
                Skip();
            }

            ProcessComment();

            // Check if we are at the end of the line.

            if (!analyzer.IsBreakOrZero())
            {
                throw new SyntaxErrorException(start, cursor.Mark(), "While scanning a directive, did not find expected comment or line break.");
            }

            // Eat a line break.

            if (analyzer.IsBreak())
            {
                SkipLine();
            }

            return directive;
        }