Пример #1
0
        /// <summary>
        /// Reads an expression wrapped in parenthesis.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <returns>Returns the expression.</returns>
        private ParenthesizedExpression GetConditionalPreprocessorParenthesizedExpression(CodeUnitProxy parentProxy)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");

            this.AdvanceToNextConditionalDirectiveCodeSymbol(parentProxy);
            var expressionProxy = new CodeUnitProxy(this.document);

            // Get the opening parenthesis.
            Symbol firstSymbol = this.symbols.Peek(1);

            if (firstSymbol == null || firstSymbol.SymbolType != SymbolType.OpenParenthesis)
            {
                throw new SyntaxException(this.document, firstSymbol.LineNumber);
            }

            this.symbols.Advance();
            var openParenthesis = new OpenParenthesisToken(this.document, firstSymbol.Text, firstSymbol.Location, this.symbols.Generated);

            expressionProxy.Children.Add(openParenthesis);

            // Get the inner expression.
            Expression expression = this.GetNextConditionalPreprocessorExpression(this.document, expressionProxy, ExpressionPrecedence.None);

            if (expression == null)
            {
                throw new SyntaxException(this.document, firstSymbol.LineNumber);
            }

            // Get the closing parenthesis.
            this.AdvanceToNextConditionalDirectiveCodeSymbol(expressionProxy);
            Symbol symbol = this.symbols.Peek(1);

            if (symbol == null || symbol.SymbolType != SymbolType.CloseParenthesis)
            {
                throw new SyntaxException(this.document, firstSymbol.LineNumber);
            }

            this.symbols.Advance();
            var closeParenthesis = new CloseParenthesisToken(this.document, symbol.Text, symbol.Location, this.symbols.Generated);

            expressionProxy.Children.Add(closeParenthesis);

            openParenthesis.MatchingBracket  = closeParenthesis;
            closeParenthesis.MatchingBracket = openParenthesis;

            // Create and return the expression.
            var parenthesizedExpression = new ParenthesizedExpression(expressionProxy, expression);

            parentProxy.Children.Add(parenthesizedExpression);

            return(parenthesizedExpression);
        }
        /// <summary>
        /// Reads an expression wrapped in parenthesis expression.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the expression.</returns>
        private ParenthesizedExpression GetParenthesizedExpression(CodeUnitProxy parentProxy, bool unsafeCode)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.Ignore(unsafeCode);

            this.AdvanceToNextCodeSymbol(parentProxy);
            var expressionProxy = new CodeUnitProxy(this.document);

            // Get the opening parenthesis.
            BracketToken openParenthesis = (BracketToken)this.GetToken(expressionProxy, TokenType.OpenParenthesis, SymbolType.OpenParenthesis);

            // Get the inner expression.
            Expression innerExpression = this.GetNextExpression(expressionProxy, ExpressionPrecedence.None, unsafeCode);
            if (innerExpression == null)
            {
                throw this.CreateSyntaxException();
            }

            // Get the closing parenthesis.
            BracketToken closeParenthesis = (BracketToken)this.GetToken(expressionProxy, TokenType.CloseParenthesis, SymbolType.CloseParenthesis);

            openParenthesis.MatchingBracket = closeParenthesis;
            closeParenthesis.MatchingBracket = openParenthesis;

            // Create and return the expression.
            var expression = new ParenthesizedExpression(expressionProxy, innerExpression);
            parentProxy.Children.Add(expression);

            return expression;
        }
        /// <summary>
        /// Reads an expression wrapped in parenthesis.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <returns>Returns the expression.</returns>
        private ParenthesizedExpression GetConditionalPreprocessorParenthesizedExpression(CodeUnitProxy parentProxy)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");

            this.AdvanceToNextConditionalDirectiveCodeSymbol(parentProxy);
            var expressionProxy = new CodeUnitProxy(this.document);

            // Get the opening parenthesis.
            Symbol firstSymbol = this.symbols.Peek(1);
            if (firstSymbol == null || firstSymbol.SymbolType != SymbolType.OpenParenthesis)
            {
                throw new SyntaxException(this.document, firstSymbol.LineNumber);
            }

            this.symbols.Advance();
            var openParenthesis = new OpenParenthesisToken(this.document, firstSymbol.Text, firstSymbol.Location, this.symbols.Generated);
            expressionProxy.Children.Add(openParenthesis);

            // Get the inner expression.
            Expression expression = this.GetNextConditionalPreprocessorExpression(this.document, expressionProxy, ExpressionPrecedence.None);
            if (expression == null)
            {
                throw new SyntaxException(this.document, firstSymbol.LineNumber);
            }

            // Get the closing parenthesis.
            this.AdvanceToNextConditionalDirectiveCodeSymbol(expressionProxy);
            Symbol symbol = this.symbols.Peek(1);
            if (symbol == null || symbol.SymbolType != SymbolType.CloseParenthesis)
            {
                throw new SyntaxException(this.document, firstSymbol.LineNumber);
            }

            this.symbols.Advance();
            var closeParenthesis = new CloseParenthesisToken(this.document, symbol.Text, symbol.Location, this.symbols.Generated);
            expressionProxy.Children.Add(closeParenthesis);

            openParenthesis.MatchingBracket = closeParenthesis;
            closeParenthesis.MatchingBracket = openParenthesis;

            // Create and return the expression.
            var parenthesizedExpression = new ParenthesizedExpression(expressionProxy, expression);
            parentProxy.Children.Add(parenthesizedExpression);

            return parenthesizedExpression;
        }