Exemple #1
0
        /// <summary>
        /// Initializes the contents of the expression.
        /// </summary>
        private void Initialize()
        {
            OpenParenthesisToken openParen = this.FindFirstChild <OpenParenthesisToken>();

            if (openParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            LiteralExpression literal = openParen.FindNextSibling <LiteralExpression>();

            if (literal == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.type.Value = CodeParser.ExtractTypeTokenFromLiteralExpression(literal);

            CloseParenthesisToken closeParen = literal.FindNextSibling <CloseParenthesisToken>();

            if (closeParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.castedExpression.Value = closeParen.FindNextSibling <Expression>();
            if (this.castedExpression.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes the contents of the statement.
        /// </summary>
        private void Initialize()
        {
            this.body.Value = this.FindFirstChildStatement();
            if (this.body.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            OpenParenthesisToken openParen = this.body.Value.FindNextSibling <OpenParenthesisToken>();

            if (openParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.condition.Value = openParen.FindNextSiblingExpression();
            if (this.condition.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            CloseParenthesisToken closeParen = this.condition.Value.FindNextSibling <CloseParenthesisToken>();

            if (closeParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes the contents of the statement.
        /// </summary>
        private void Initialize()
        {
            OpenParenthesisToken openParen = this.FindFirstChild <OpenParenthesisToken>();

            if (openParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.fixedVariable.Value = openParen.FindNextSibling <VariableDeclarationExpression>();
            if (this.fixedVariable.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            CloseParenthesisToken closeParen = this.fixedVariable.Value.FindNextSibling <CloseParenthesisToken>();

            if (closeParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.body.Value = closeParen.FindNextSiblingStatement();
            if (this.body.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }
        }
Exemple #4
0
        /// <summary>
        /// Initializes the contents of the statement.
        /// </summary>
        private void Initialize()
        {
            OpenParenthesisToken openParen = this.FindFirstChild <OpenParenthesisToken>();

            if (openParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.switchExpression.Value = openParen.FindNextSiblingExpression();
            if (this.switchExpression.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            CloseParenthesisToken closeParen = this.switchExpression.Value.FindNextSibling <CloseParenthesisToken>();

            if (closeParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.defaultStatement.Value = null;
            List <SwitchCaseStatement> caseList = new List <SwitchCaseStatement>();

            for (CodeUnit c = closeParen.FindNextSibling(); c != null; c = c.FindNext())
            {
                if (c.Is(StatementType.SwitchCase))
                {
                    caseList.Add((SwitchCaseStatement)c);
                }
                else if (c.Is(StatementType.SwitchDefault))
                {
                    if (this.defaultStatement.Value != null)
                    {
                        throw new SyntaxException(this.Document, this.LineNumber);
                    }

                    this.defaultStatement.Value = (SwitchDefaultStatement)c;
                    break;
                }
                else if (c.Is(TokenType.OpenCurlyBracket))
                {
                    if (caseList.Count > 0 || this.defaultStatement.Value != null)
                    {
                        throw new SyntaxException(this.Document, this.LineNumber);
                    }
                }
                else if (!c.Is(CodeUnitType.LexicalElement) || c.Is(LexicalElementType.Token))
                {
                    break;
                }
            }

            this.caseStatements.Value = caseList.AsReadOnly();
        }
Exemple #5
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);
        }
Exemple #6
0
        /// <summary>
        /// Initializes the contents of the statement.
        /// </summary>
        private void Initialize()
        {
            OpenParenthesisToken openParen = this.FindFirstChild <OpenParenthesisToken>();

            if (openParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.initializers.Value = this.FindInitializers(openParen);
            if (this.initializers.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            SemicolonToken semicolon = openParen.FindNextSibling <SemicolonToken>();

            if (semicolon == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.condition.Value = this.FindCondition(semicolon);

            semicolon = semicolon.FindNextSibling <SemicolonToken>();
            if (semicolon == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.iterators.Value = this.FindIterators(semicolon);
            if (this.iterators.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            CloseParenthesisToken closeParen = semicolon.FindNextSibling <CloseParenthesisToken>();

            if (closeParen == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            this.body.Value = closeParen.FindNextSiblingStatement();
            if (this.body.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }
        }
Exemple #7
0
        /// <summary>
        /// Initializes the contents of the statement.
        /// </summary>
        private void Initialize()
        {
            OpenParenthesisToken openParen = this.FindFirstChild <OpenParenthesisToken>();

            if (openParen == null)
            {
                this.condition.Value = null;
                this.body.Value      = this.FindFirstChildStatement();
            }
            else
            {
                this.condition.Value = openParen.FindNextSiblingExpression();
                if (this.condition.Value == null)
                {
                    throw new SyntaxException(this.Document, this.LineNumber);
                }

                CloseParenthesisToken closeParen = this.condition.Value.FindNextSibling <CloseParenthesisToken>();
                if (closeParen == null)
                {
                    throw new SyntaxException(this.Document, this.LineNumber);
                }

                this.body.Value = closeParen.FindNextSiblingStatement();
            }

            if (this.body.Value == null)
            {
                throw new SyntaxException(this.Document, this.LineNumber);
            }

            // Look for another attached else statement.
            this.elseStatement.Value = null;

            for (CodeUnit c = this.FindNextSibling(); c != null; c = c.FindNext())
            {
                if (c.Is(StatementType.Else))
                {
                    this.elseStatement.Value = (ElseStatement)c;
                }
                else if (!c.Is(CodeUnitType.LexicalElement) || c.Is(LexicalElementType.Token))
                {
                    break;
                }
            }
        }
        /// <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;
        }