示例#1
0
        /// <summary>
        /// Initializes a new instance of the TryStatement class.
        /// </summary>
        /// <param name="embeddedStatement">
        /// The statement embedded within this try-statement.
        /// </param>
        internal TryStatement(BlockStatement embeddedStatement)
            : base(StatementType.Try)
        {
            Param.AssertNotNull(embeddedStatement, "embeddedStatement");

            this.embeddedStatement = embeddedStatement;
            this.AddStatement(embeddedStatement);
        }
示例#2
0
        /// <summary>
        /// Reads the next block statement from the file and returns it.
        /// </summary>
        /// <param name="unsafeCode">
        /// Indicates whether the code being parsed resides in an unsafe code block.
        /// </param>
        /// <returns>
        /// Returns the statement.
        /// </returns>
        private BlockStatement ParseBlockStatement(bool unsafeCode)
        {
            Param.Ignore(unsafeCode);

            Reference<ICodePart> statementReference = new Reference<ICodePart>();

            // Get the opening bracket keyword.
            Bracket openingBracket = this.GetBracketToken(CsTokenType.OpenCurlyBracket, SymbolType.OpenCurlyBracket, statementReference);
            Node<CsToken> openingBracketNode = this.tokens.InsertLast(openingBracket);

            // Create the block statement.
            BlockStatement block = new BlockStatement();

            // Get the rest of the statement.
            Node<CsToken> closingBracketNode = this.ParseStatementScope(block, statementReference, unsafeCode);
            if (closingBracketNode == null)
            {
                // If we failed to get a closing bracket back, then there is a syntax
                // error in the document since there is an opening bracket with no matching
                // closing bracket.
                throw this.CreateSyntaxException();
            }

            openingBracket.MatchingBracketNode = closingBracketNode;
            ((Bracket)closingBracketNode.Value).MatchingBracketNode = openingBracketNode;

            // Create the token list for this statement.
            CsTokenList partialTokens = new CsTokenList(this.tokens, openingBracketNode, this.tokens.Last);

            block.Tokens = partialTokens;
            statementReference.Target = block;

            return block;
        }
 /// <summary>
 /// The save.
 /// </summary>
 /// <param name="blockStatement">
 /// The block statement.
 /// </param>
 private void Save(BlockStatement blockStatement)
 {
     this.Save((ICodeUnit)blockStatement);
 }