示例#1
0
        private LineSpanDirectiveTriviaSyntax ParseLineSpanDirective(SyntaxToken hash, SyntaxToken lineKeyword, bool isActive)
        {
            Debug.Assert(CurrentToken.Kind == SyntaxKind.OpenParenToken);

            bool reportError = isActive;
            var  start       = ParseLineDirectivePosition(ref reportError, out int startLine, out int startCharacter);

            if (noTriviaBetween(lineKeyword, start.GetFirstToken()))
            {
                start = this.AddError(start, ErrorCode.ERR_LineSpanDirectiveRequiresSpace);
            }

            var minus = EatToken(SyntaxKind.MinusToken, reportError: reportError);

            if (minus.IsMissing)
            {
                reportError = false;
            }

            var end = ParseLineDirectivePosition(ref reportError, out int endLine, out int endCharacter);

            if (reportError &&
                (endLine < startLine || (endLine == startLine && endCharacter < startCharacter)))
            {
                end = this.AddError(end, ErrorCode.ERR_LineSpanDirectiveEndLessThanStart);
            }

            var characterOffset = (CurrentToken.Kind == SyntaxKind.NumericLiteralToken) ?
                                  ParseLineDirectiveNumericLiteral(ref reportError, minValue: 1, maxValue: MaxCharacterValue, out _) :
                                  null;

            if (noTriviaBetween(end.GetLastToken(), characterOffset))
            {
                characterOffset = this.AddError(characterOffset, ErrorCode.ERR_LineSpanDirectiveRequiresSpace);
            }

            var file = EatToken(SyntaxKind.StringLiteralToken, ErrorCode.ERR_MissingPPFile, reportError: reportError);

            if (file.IsMissing)
            {
                reportError = false;
            }

            if (noTriviaBetween(characterOffset ?? end.GetLastToken(), file))
            {
                file = this.AddError(file, ErrorCode.ERR_LineSpanDirectiveRequiresSpace);
            }

            var endOfDirective = this.ParseEndOfDirective(ignoreErrors: !reportError);

            return(SyntaxFactory.LineSpanDirectiveTrivia(hash, lineKeyword, start, minus, end, characterOffset, file, endOfDirective, isActive));
示例#2
0
        private LineSpanDirectiveTriviaSyntax ParseLineSpanDirective(SyntaxToken hash, SyntaxToken lineKeyword, bool isActive)
        {
            Debug.Assert(CurrentToken.Kind == SyntaxKind.OpenParenToken);

            if (isActive)
            {
                lineKeyword = CheckFeatureAvailability(lineKeyword, MessageID.IDS_FeatureLineSpanDirective);
            }

            bool reportError = isActive;
            var  start       = ParseLineDirectivePosition(ref reportError, out int startLine, out int startCharacter);

            var minus = EatToken(SyntaxKind.MinusToken, reportError: reportError);

            if (minus.IsMissing)
            {
                reportError = false;
            }

            var end = ParseLineDirectivePosition(ref reportError, out int endLine, out int endCharacter);

            if (reportError &&
                (endLine < startLine || (endLine == startLine && endCharacter < startCharacter)))
            {
                end = this.AddError(end, ErrorCode.ERR_LineSpanDirectiveEndLessThanStart);
            }

            var characterOffset = (CurrentToken.Kind == SyntaxKind.NumericLiteralToken) ?
                                  ParseLineDirectiveNumericLiteral(ref reportError, minValue: 1, maxValue: MaxCharacterValue, out _) :
                                  null;

            var file = EatToken(SyntaxKind.StringLiteralToken, ErrorCode.ERR_MissingPPFile, reportError: reportError);

            if (file.IsMissing)
            {
                reportError = false;
            }

            var endOfDirective = this.ParseEndOfDirective(ignoreErrors: !reportError);

            return(SyntaxFactory.LineSpanDirectiveTrivia(hash, lineKeyword, start, minus, end, characterOffset, file, endOfDirective, isActive));
        }