Example #1
0
 internal static SyntaxToken MissingToken(
     GreenNode leading,
     SyntaxKind kind,
     GreenNode trailing
     )
 {
     return(SyntaxToken.CreateMissing(kind, leading, trailing));
 }
Example #2
0
 internal static SyntaxToken MissingToken(SyntaxKind kind)
 {
     return(SyntaxToken.CreateMissing(kind, null, null));
 }
        private TryStatementSyntax ParseTryStatement()
        {
            var isInTry = this._isInTry;

            this._isInTry = true;

            var @try = this.EatToken(SyntaxKind.TryKeyword);

            BlockSyntax block;

            if (@try.IsMissing)
            {
                block = _syntaxFactory.Block(this.EatToken(SyntaxKind.OpenBraceToken), default(SyntaxList <StatementSyntax>), this.EatToken(SyntaxKind.CloseBraceToken));
            }
            else
            {
                var saveTerm = this._termState;
                this._termState |= TerminatorState.IsEndOfTryBlock;
                block            = this.ParseBlock();
                this._termState  = saveTerm;
            }

            var catches = default(SyntaxListBuilder <CatchClauseSyntax>);
            FinallyClauseSyntax @finally = null;

            try
            {
                bool hasEnd      = false;
                bool hasCatchAll = false;

                if (this.CurrentToken.Kind == SyntaxKind.CatchKeyword)
                {
                    hasEnd  = true;
                    catches = this._pool.Allocate <CatchClauseSyntax>();
                    while (this.CurrentToken.Kind == SyntaxKind.CatchKeyword)
                    {
                        var clause = this.ParseCatchClause(hasCatchAll);
                        hasCatchAll |= clause.Declaration == null && clause.Filter == null;
                        catches.Add(clause);
                    }
                }

                if (this.CurrentToken.Kind == SyntaxKind.FinallyKeyword)
                {
                    hasEnd = true;
                    var fin      = this.EatToken();
                    var finBlock = this.ParseBlock();
                    @finally = _syntaxFactory.FinallyClause(fin, finBlock);
                }

                if (!hasEnd)
                {
                    block = this.AddErrorToLastToken(block, ErrorCode.ERR_ExpectedEndTry);

                    // synthesize missing tokens for "finally { }":
                    @finally = _syntaxFactory.FinallyClause(
                        SyntaxToken.CreateMissing(SyntaxKind.FinallyKeyword, null, null),
                        _syntaxFactory.Block(
                            SyntaxToken.CreateMissing(SyntaxKind.OpenBraceToken, null, null),
                            default(SyntaxList <StatementSyntax>),
                            SyntaxToken.CreateMissing(SyntaxKind.CloseBraceToken, null, null)));
                }

                this._isInTry = isInTry;

                return(_syntaxFactory.TryStatement(@try, block, catches, @finally));
            }
            finally
            {
                if (!catches.IsNull)
                {
                    this._pool.Free(catches);
                }
            }
        }