Exemplo n.º 1
0
        private DirectiveTriviaSyntax ParseNullableDirective(SyntaxToken hash, SyntaxToken token, bool isActive)
        {
            if (isActive)
            {
                token = CheckFeatureAvailability(token, MessageID.IDS_FeatureNullableReferenceTypes);
            }

            SyntaxToken setting = this.CurrentToken.Kind switch
            {
                SyntaxKind.EnableKeyword => EatToken(),
                SyntaxKind.DisableKeyword => EatToken(),
                SyntaxKind.RestoreKeyword => EatToken(),
                _ => EatToken(SyntaxKind.DisableKeyword, ErrorCode.ERR_NullableDirectiveQualifierExpected, reportError: isActive)
            };

            SyntaxToken target = this.CurrentToken.Kind switch
            {
                SyntaxKind.WarningsKeyword => EatToken(),
                SyntaxKind.AnnotationsKeyword => EatToken(),
                SyntaxKind.EndOfDirectiveToken => null,
                SyntaxKind.EndOfFileToken => null,
                _ => EatToken(SyntaxKind.WarningsKeyword, ErrorCode.ERR_NullableDirectiveTargetExpected, reportError: !setting.IsMissing && isActive)
            };

            var end = this.ParseEndOfDirective(ignoreErrors: setting.IsMissing || target?.IsMissing == true || !isActive);

            return(SyntaxFactory.NullableDirectiveTrivia(hash, token, setting, target, end, isActive));
        }
Exemplo n.º 2
0
        private DirectiveTriviaSyntax ParseNullableDirective(SyntaxToken hash, SyntaxToken token, bool isActive)
        {
            if (isActive)
            {
                token = CheckFeatureAvailability(token, MessageID.IDS_FeatureNullableReferenceTypes);
            }

            SyntaxToken setting;

            switch (this.CurrentToken.Kind)
            {
            case SyntaxKind.EnableKeyword:
            case SyntaxKind.DisableKeyword:
            case SyntaxKind.SafeOnlyKeyword:
            case SyntaxKind.RestoreKeyword:
                setting = EatToken();
                break;

            default:
                setting = EatToken(SyntaxKind.DisableKeyword, ErrorCode.ERR_NullableDirectiveQualifierExpected, reportError: isActive);
                break;
            }

            var end = this.ParseEndOfDirective(ignoreErrors: setting.IsMissing || !isActive);

            return(SyntaxFactory.NullableDirectiveTrivia(hash, token, setting, end, isActive));
        }
Exemplo n.º 3
0
        private DirectiveTriviaSyntax ParseNullableDirective(SyntaxToken hash, SyntaxToken token, bool isActive)
        {
            token = CheckFeatureAvailability(token, MessageID.IDS_FeatureNullableReferenceTypes);
            var setting = (this.CurrentToken.Kind == SyntaxKind.EnableKeyword || this.CurrentToken.Kind == SyntaxKind.DisableKeyword) ?
                          EatToken() :
                          EatToken(SyntaxKind.DisableKeyword, ErrorCode.ERR_NullableDirectiveQualifierExpected, reportError: isActive);
            var end = this.ParseEndOfDirective(ignoreErrors: setting.IsMissing || !isActive);

            return(SyntaxFactory.NullableDirectiveTrivia(hash, token, setting, end, isActive));
        }