コード例 #1
0
        /// <summary>
        /// Reads the next default-statement from the file and returns it.
        /// </summary>
        /// <param name="parentReference">The parent code unit.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the statement.</returns>
        private SwitchDefaultStatement ParseSwitchDefaultStatement(Reference<ICodePart> parentReference, bool unsafeCode)
        {
            Param.AssertNotNull(parentReference, "parentReference");
            Param.Ignore(unsafeCode);

            var statementReference = new Reference<ICodePart>();

            // Move past the default keyword.
            CsToken firstToken = this.GetToken(CsTokenType.Default, SymbolType.Default, parentReference, statementReference);
            Node<CsToken> firstTokenNode = this.tokens.InsertLast(firstToken);

            // Get the colon.
            this.tokens.Add(this.GetToken(CsTokenType.LabelColon, SymbolType.Colon, statementReference));

            // Create the statement.
            SwitchDefaultStatement defaultStatement = new SwitchDefaultStatement();

            // Get each of the sub-statements beneath this statement.
            while (true)
            {
                // Check the type of the next symbol.
                Symbol symbol = this.GetNextSymbol(statementReference);

                // Check if we've reached the end of the default statement.
                if (symbol.SymbolType == SymbolType.CloseCurlyBracket ||
                    symbol.SymbolType == SymbolType.Case ||
                    symbol.SymbolType == SymbolType.Default)
                {
                    break;
                }

                // Read the next child statement.
                Statement statement = this.GetNextStatement(statementReference, unsafeCode, defaultStatement.Variables);
                if (statement == null)
                {
                    throw this.CreateSyntaxException();
                }

                // Add it to the default statement.
                defaultStatement.AddStatement(statement);
            }

            // Create the token list for the default statement.
            defaultStatement.Tokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last);

            statementReference.Target = defaultStatement;
            return defaultStatement;
        }
コード例 #2
0
ファイル: CodeParser.cs プロジェクト: katerina-marchenkova/my
 private SwitchDefaultStatement ParseSwitchDefaultStatement(bool unsafeCode)
 {
     CsToken item = this.GetToken(CsTokenType.Default, SymbolType.Default);
     Microsoft.StyleCop.Node<CsToken> firstItemNode = this.tokens.InsertLast(item);
     this.tokens.Add(this.GetToken(CsTokenType.LabelColon, SymbolType.Colon));
     SwitchDefaultStatement statement = new SwitchDefaultStatement();
     while (true)
     {
         Symbol nextSymbol = this.GetNextSymbol();
         if (((nextSymbol.SymbolType == SymbolType.CloseCurlyBracket) || (nextSymbol.SymbolType == SymbolType.Case)) || (nextSymbol.SymbolType == SymbolType.Default))
         {
             break;
         }
         Statement nextStatement = this.GetNextStatement(unsafeCode, statement.Variables);
         if (nextStatement == null)
         {
             throw this.CreateSyntaxException();
         }
         statement.AddStatement(nextStatement);
     }
     statement.Tokens = new CsTokenList(this.tokens, firstItemNode, this.tokens.Last);
     return statement;
 }