Example #1
0
        public override IElement CreateCopy()
        {
            ForEachStatement e = new ForEachStatement();

            e.AddChildren(this.CopyChildren());

            e._foreachKeyword = (Token)e.children[this.children.IndexOf(_foreachKeyword)];
            e._foreachGroup   = (ParenthesesGroup)e.children[this.children.IndexOf(_foreachGroup)];
            e._currentVar     = (VarName)e._foreachGroup.GetChildren()[this._foreachGroup.GetChildren().IndexOf(_currentVar)];
            e._array          = (Expression)e._foreachGroup.GetChildren()[this._foreachGroup.GetChildren().IndexOf(_array)];

            e._statement = (Statement)e.children[this.children.IndexOf(_statement)];

            return(e);
        }
Example #2
0
        public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            IElement next = parentInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (next == null)
            {
                return(false);
            }

            if (DevCode.Check(parentInfo, parsingInfo, scriptInfo) ||
                PreProcessorRegion.Check(parentInfo, parsingInfo, scriptInfo))
            {
                return(true);
            }

            if (EmptyStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                BlockStatement.Check(parentInfo, parsingInfo, scriptInfo)
                )
            {
                return(true);
            }

            if (IfElseStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                SwitchStatement.Check(parentInfo, parsingInfo, scriptInfo)

                || WhileStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                DoWhileStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                ForStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                ForEachStatement.Check(parentInfo, parsingInfo, scriptInfo)

                || ReturnStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                BreakStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                ContinueStatement.Check(parentInfo, parsingInfo, scriptInfo)

                || WaitStatement.Check(parentInfo, parsingInfo, scriptInfo) ||
                WaittillFrameEndStatement.Check(parentInfo, parsingInfo, scriptInfo)
                )
            {
                return(true);
            }

            if (ExpressionStatement.Check(parentInfo, parsingInfo, scriptInfo, true)) // nikdy nevráti false?
            {
                return(true);
            }

            return(false);
        }
Example #3
0
        private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo)
        {
            ForEachStatement foreachStatement = new ForEachStatement();
            MoveInfo         moveInfo         = new MoveInfo(parentInfo);

            foreachStatement._foreachKeyword = (Token)moveInfo.Current;

            // expression
            IElement expGroupTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (expGroupTry == null || !(expGroupTry is ParenthesesGroup))
            {
                throw new SyntaxException("Could not find foreach expression", parentInfo.GetErrorInfo());
            }

            ParenthesesGroup expGroup     = (ParenthesesGroup)expGroupTry;
            MoveInfo         expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo);

            foreachStatement._foreachGroup = expGroup;

            // var define
            IElement tryVar = expGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            if (tryVar == null || !tryVar.IsTT(TokenType.Word))
            {
                throw new SyntaxException("Could not parse foreach var", parentInfo.GetErrorInfo());
            }

            VarName.Parse(expGroupInfo, parsingInfo, scriptInfo);
            VarName varName = (VarName)expGroupInfo.Current;

            LocalVarInfo localVar = parsingInfo.CurrentFunc.LocalVars.Find(a => a.Name.EqualCode(tryVar.ToString()));     // there is already var with this name...

            if (localVar == null)
            {
                parsingInfo.CurrentFunc.LocalVars.Add(new LocalVarInfo(scriptInfo.SF, tryVar.ToString(), tryVar.CharIndex, tryVar.CharLength, null, varName));
            }

            foreachStatement._currentVar = varName;

            // in keyword
            IElement tryIn = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight);

            if (tryIn == null || !tryIn.IsTT(TokenType.Word) || !tryIn.ToString().EqualCode("in"))
            {
                throw new SyntaxException("Could not find foreach 'in'", parentInfo.GetErrorInfo());
            }

            // array
            IElement   tryArray    = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight);
            Expression tryArrayExp = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo);

            if (tryArrayExp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null)
            {
                throw new SyntaxException("Could not parse foreach array", parentInfo.GetErrorInfo());
            }

            foreachStatement._array = tryArrayExp;

            // statement
            moveInfo.FindNextBlack(SearchDirection.LeftToRight);
            if (!Statement.Check(moveInfo, parsingInfo, scriptInfo))
            {
                throw new SyntaxException("Could not parse foreach statement", parentInfo.GetErrorInfo());
            }

            foreachStatement._statement = (Statement)moveInfo.Current;

            // build
            int startIndex = parentInfo.CurrentIndex;
            int length     = (moveInfo.CurrentIndex + 1) - startIndex;

            foreachStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length));
            parentInfo.Replace(length, foreachStatement);
        }