ShaderTools.Hlsl.Parser.DirectiveParser.ParseEndOfDirective C# (CSharp) Method

ParseEndOfDirective() private method

private ParseEndOfDirective ( bool ignoreErrors, bool afterLineNumber = false ) : SyntaxToken
ignoreErrors bool
afterLineNumber bool
return SyntaxToken
        private SyntaxToken ParseEndOfDirective(bool ignoreErrors, bool afterLineNumber = false)
        {
            var skippedTokens = new List<SyntaxToken>();

            // Consume all extranous tokens as leading SkippedTokens trivia.
            if (Current.Kind != SyntaxKind.EndOfDirectiveToken &&
                Current.Kind != SyntaxKind.EndOfFileToken)
            {
                skippedTokens = new List<SyntaxToken>(10);

                if (!ignoreErrors)
                {
                    var errorCode = DiagnosticId.EndOfPreprocessorLineExpected;
                    if (afterLineNumber)
                        errorCode = DiagnosticId.MissingPreprocessorFile;

                    skippedTokens.Add(WithDiagnostic(NextToken().WithoutDiagnostics(), errorCode));
                }

                while (Current.Kind != SyntaxKind.EndOfDirectiveToken &&
                       Current.Kind != SyntaxKind.EndOfFileToken)
                {
                    skippedTokens.Add(NextToken().WithoutDiagnostics());
                }
            }

            // attach text from extraneous tokens as trivia to EndOfDirective token
            var endOfDirective = Current.Kind == SyntaxKind.EndOfDirectiveToken
                ? NextToken()
                : new SyntaxToken(SyntaxKind.EndOfDirectiveToken, true,
                    GetDiagnosticSourceRangeForMissingToken(),
                    GetDiagnosticTextSpanForMissingToken());

            if (skippedTokens.Any())
                endOfDirective = endOfDirective.WithLeadingTrivia(new[] { new SkippedTokensTriviaSyntax(skippedTokens.ToList()) });

            return endOfDirective;
        }