Esempio n. 1
0
        private DirectiveTriviaSyntax ParseLineDirective(
            SyntaxToken hash,
            SyntaxToken id,
            bool isActive
            )
        {
            SyntaxToken line;
            SyntaxToken file = null;
            bool        sawLineButNotFile = false;

            switch (this.CurrentToken.Kind)
            {
            case SyntaxKind.DefaultKeyword:
            case SyntaxKind.HiddenKeyword:
                line = this.EatToken();
                break;

            default:
                line = this.EatToken(
                    SyntaxKind.NumericLiteralToken,
                    ErrorCode.ERR_InvalidLineNumber,
                    reportError: isActive
                    );
                sawLineButNotFile = true;     //assume this is the case until we (potentially) see the file name below
                if (isActive && !line.IsMissing && line.Kind == SyntaxKind.NumericLiteralToken)
                {
                    if ((int)line.Value < 1)
                    {
                        line = this.AddError(line, ErrorCode.ERR_InvalidLineNumber);
                    }
                    else if ((int)line.Value > 0xfeefed)
                    {
                        line = this.AddError(line, ErrorCode.WRN_TooManyLinesForDebugger);
                    }
                }

                if (
                    this.CurrentToken.Kind == SyntaxKind.StringLiteralToken &&
                    (
                        line.IsMissing ||
                        line.GetTrailingTriviaWidth() > 0 ||
                        this.CurrentToken.GetLeadingTriviaWidth() > 0
                    )
                    ) //require separation between line number and file name
                {
                    file = this.EatToken();
                    sawLineButNotFile = false;
                }
                break;
            }

            var end = this.ParseEndOfDirective(
                ignoreErrors: line.IsMissing || !isActive,
                afterLineNumber: sawLineButNotFile
                );

            return(SyntaxFactory.LineDirectiveTrivia(hash, id, line, file, end, isActive));
        }