/// <summary> /// Reads the next while-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 WhileStatement ParseWhileStatement(Reference<ICodePart> parentReference, bool unsafeCode) { Param.AssertNotNull(parentReference, "parentReference"); Param.Ignore(unsafeCode); var statementReference = new Reference<ICodePart>(); // Add the while keyword. CsToken firstToken = this.GetToken(CsTokenType.While, SymbolType.While, parentReference, statementReference); Node<CsToken> firstTokenNode = this.tokens.InsertLast(firstToken); // Get the opening parenthesis. Bracket openParenthesis = this.GetBracketToken(CsTokenType.OpenParenthesis, SymbolType.OpenParenthesis, statementReference); Node<CsToken> openParenthesisNode = this.tokens.InsertLast(openParenthesis); // Get the expression within the parenthesis. Expression expression = this.GetNextExpression(ExpressionPrecedence.None, statementReference, unsafeCode); if (expression == null) { throw this.CreateSyntaxException(); } // Get the closing parenthesis. Bracket closeParenthesis = this.GetBracketToken(CsTokenType.CloseParenthesis, SymbolType.CloseParenthesis, statementReference); Node<CsToken> closeParenthesisNode = this.tokens.InsertLast(closeParenthesis); openParenthesis.MatchingBracketNode = closeParenthesisNode; closeParenthesis.MatchingBracketNode = openParenthesisNode; // Get the embedded statement. Statement childStatement = this.GetNextStatement(statementReference, unsafeCode); if (childStatement == null) { throw new SyntaxException(this.document.SourceCode, firstToken.LineNumber); } // Create the token list for the statement. CsTokenList partialTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last); // Create and return the while-statement. WhileStatement statement = new WhileStatement(partialTokens, expression); statement.EmbeddedStatement = childStatement; statementReference.Target = statement; return statement; }
private WhileStatement ParseWhileStatement(bool unsafeCode) { CsToken item = this.GetToken(CsTokenType.While, SymbolType.While); Microsoft.StyleCop.Node<CsToken> firstItemNode = this.tokens.InsertLast(item); Bracket bracketToken = this.GetBracketToken(CsTokenType.OpenParenthesis, SymbolType.OpenParenthesis); Microsoft.StyleCop.Node<CsToken> node2 = this.tokens.InsertLast(bracketToken); Expression nextExpression = this.GetNextExpression(ExpressionPrecedence.None, unsafeCode); if (nextExpression == null) { throw this.CreateSyntaxException(); } Bracket bracket2 = this.GetBracketToken(CsTokenType.CloseParenthesis, SymbolType.CloseParenthesis); Microsoft.StyleCop.Node<CsToken> node3 = this.tokens.InsertLast(bracket2); bracketToken.MatchingBracketNode = node3; bracket2.MatchingBracketNode = node2; Statement nextStatement = this.GetNextStatement(unsafeCode); if (nextStatement == null) { throw new SyntaxException(this.document.SourceCode, item.LineNumber); } CsTokenList tokens = new CsTokenList(this.tokens, firstItemNode, this.tokens.Last); WhileStatement statement2 = new WhileStatement(tokens, nextExpression); statement2.EmbeddedStatement = nextStatement; return statement2; }