Beispiel #1
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);
            }
        }
Beispiel #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();
        }
Beispiel #3
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;
                }
            }
        }