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()
        {
            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 #3
0
        /// <summary>
        /// Initializes the contents of the statement.
        /// </summary>
        private void Initialize()
        {
            CodeUnit start = this.FindFirstChild <OpenParenthesisToken>();

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

            Expression expression = start.FindNextSiblingExpression();

            if (expression != null)
            {
                this.catchExpression.Value = expression;

                if (expression.ExpressionType == ExpressionType.Literal)
                {
                    this.exceptionType.Value = CodeParser.ExtractTypeTokenFromLiteralExpression((LiteralExpression)expression);
                }
                else if (expression.ExpressionType == ExpressionType.VariableDeclaration)
                {
                    VariableDeclarationExpression variableDeclaration = (VariableDeclarationExpression)expression;

                    this.exceptionType.Value = variableDeclaration.Type;

                    foreach (VariableDeclaratorExpression declarator in variableDeclaration.Declarators)
                    {
                        this.identifier.Value = declarator.Identifier.Text;
                        break;
                    }
                }

                start = expression;
            }

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

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

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

            // Look for the try-statement that this catch-statement is attached to.
            this.tryStatement.Value = null;

            for (CodeUnit c = this.FindPreviousSibling(); c != null; c = c.FindNext())
            {
                if (c.Is(StatementType.Try))
                {
                    this.tryStatement.Value = (TryStatement)c;
                }
                else if (!c.Is(StatementType.Catch) && (!c.Is(CodeUnitType.LexicalElement) || c.Is(LexicalElementType.Token)))
                {
                    break;
                }
            }

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