Пример #1
0
        void ProcessArrayFor(ParsingScript script,string forString)
        {
            int index = forString.IndexOf(Constants.FOR_EACH);

            if (index <= 0 || index == forString.Length - 1)
            {
                throw new ArgumentException("Expecting: for(item : array)");
            }

            string varName = forString.Substring(0,index);

            ParsingScript forScript  = new ParsingScript(forString);
            Variable      arrayValue = forScript.ExecuteFrom(index + 1);

            int cycles            = arrayValue.TotalElements();
            int startForCondition = script.Pointer;

            for (int i = 0; i < cycles; i++)
            {
                script.Pointer = startForCondition;
                Variable current = arrayValue.GetValue(i);
                ParserFunction.AddGlobalOrLocalVariable(varName,
                                                        new GetVarFunction(current));
                Variable result = ProcessBlock(script);
                if (result.IsReturn || result.Type == Variable.VarType.BREAK)
                {
                    script.Pointer = startForCondition;
                    SkipBlock(script);
                    return;
                }
            }
        }
Пример #2
0
        async Task ProcessArrayForAsync(ParsingScript script, string forString)
        {
            int index = forString.IndexOf(Constants.FOR_EACH);

            if (index <= 0 || index == forString.Length - 1)
            {
                throw new ArgumentException("Expecting: for(item : array)");
            }

            string varName = forString.Substring(0, index);

            ParsingScript forScript = new ParsingScript(forString, 0, script.Char2Line);

            forScript.ParentScript = script;
            forScript.Filename     = script.Filename;
            forScript.Debugger     = script.Debugger;
            forScript.Pointer      = index + 1;
            Variable arrayValue = await Utils.GetItemAsync(forScript);

            int cycles = arrayValue.Count;

            if (cycles == 0)
            {
                SkipBlock(script);
                return;
            }
            int startForCondition = script.Pointer;

            for (int i = 0; i < cycles; i++)
            {
                script.Pointer = startForCondition;
                Variable current = arrayValue.GetValue(i);
                ParserFunction.AddGlobalOrLocalVariable(varName,
                                                        new GetVarFunction(current));
                Variable result = await ProcessBlockAsync(script);

                if (result.IsReturn || result.Type == Variable.VarType.BREAK)
                {
                    //script.Pointer = startForCondition;
                    //SkipBlock(script);
                    //return;
                    break;
                }
            }
            script.Pointer = startForCondition;
            SkipBlock(script);
        }