Пример #1
0
        protected override Variable Evaluate(ParsingScript script)
        {
            // 1. Get the name of the variable.
            string varName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY);

            Utils.CheckNotEnd(script, Constants.CONTAINS);

            // 2. Get the current value of the variable.
            List <Variable> arrayIndices = Utils.GetArrayIndices(ref varName);

            ParserFunction func = ParserFunction.GetFunction(varName);

            Utils.CheckNotNull(varName, func);
            Variable currentValue = func.GetValue(script);

            // 2b. Special dealings with arrays:
            Variable query = arrayIndices.Count > 0 ?
                             Utils.ExtractArrayElement(currentValue, arrayIndices) :
                             currentValue;

            // 3. Get the value to be looked for.
            Variable searchValue = Utils.GetItem(script);

            Utils.CheckNotEnd(script, Constants.CONTAINS);

            // 4. Check if the value to search for exists.
            bool exists = query.Exists(searchValue, true /* notEmpty */);

            script.MoveBackIf(Constants.START_GROUP);
            return(new Variable(exists));
        }
Пример #2
0
        protected override Variable Evaluate(ParsingScript script)
        {
            bool isList;

            List <Variable> functionArgs = Utils.GetArgs(script,
                                                         Constants.START_ARG, Constants.END_ARG, out isList);

            //script.MoveForwardIf(Constants.END_ARG);
            script.MoveBackIf(Constants.START_GROUP);

            if (functionArgs.Count != m_args.Length)
            {
                throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " +
                                            m_args.Length + " declared, " + functionArgs.Count + " supplied");
            }

            // 1. Add passed arguments as local variables to the Parser.
            StackLevel stackLevel = new StackLevel(m_name);

            for (int i = 0; i < m_args.Length; i++)
            {
                stackLevel.Variables[m_args[i]] = new GetVarFunction(functionArgs[i]);
            }

            ParserFunction.AddLocalVariables(stackLevel);

            // 2. Execute the body of the function.
            Variable      result     = null;
            ParsingScript tempScript = new ParsingScript(m_body);

            tempScript.ScriptOffset = m_parentOffset;
            if (m_parentScript != null)
            {
                tempScript.Char2Line      = m_parentScript.Char2Line;
                tempScript.Filename       = m_parentScript.Filename;
                tempScript.OriginalScript = m_parentScript.OriginalScript;
            }

            while (tempScript.Pointer < m_body.Length - 1 &&
                   (result == null || !result.IsReturn))
            {
                result = tempScript.ExecuteTo();
                tempScript.GoToNextStatement();
            }

            ParserFunction.PopLocalVariables();
            //script.MoveForwardIf(Constants.END_ARG);
            //script.MoveForwardIf(Constants.END_STATEMENT);

            if (result == null)
            {
                result = Variable.EmptyInstance;
            }
            else
            {
                result.IsReturn = false;
            }

            return(result);
        }
Пример #3
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            script.MoveBackIf(Constants.START_GROUP);

            if (args.Count != m_args.Length)
            {
                throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " +
                                            m_args.Length + " declared, " + args.Count + " supplied");
            }

            // 1. Add passed arguments as local variables to the Parser.
            RegisterArguments(args);

            // 2. Execute the body of the function.
            Variable      result     = null;
            ParsingScript tempScript = new ParsingScript(m_body);

            tempScript.ScriptOffset = m_parentOffset;
            if (m_parentScript != null)
            {
                tempScript.Char2Line      = m_parentScript.Char2Line;
                tempScript.Filename       = m_parentScript.Filename;
                tempScript.OriginalScript = m_parentScript.OriginalScript;
            }
            tempScript.ParentScript = script;
            tempScript.InTryBlock   = script.InTryBlock;

            if (script.Debugger != null)
            {
                result = script.Debugger.StepInFunctionIfNeeded(tempScript);
            }

            while (tempScript.Pointer < m_body.Length - 1 &&
                   (result == null || !result.IsReturn))
            {
                result = tempScript.ExecuteTo();
                tempScript.GoToNextStatement();
            }

            ParserFunction.PopLocalVariables();

            if (result == null)
            {
                result = Variable.EmptyInstance;
            }
            else
            {
                result.IsReturn = false;
            }

            return(result);
        }
Пример #4
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List<Variable> args = script.GetFunctionArgs();
            script.MoveBackIf(Constants.START_GROUP);

            if (args.Count != m_args.Length)
            {
                throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " +
                                    m_args.Length + " declared, " + args.Count + " supplied");
            }

            Variable result = Run(args);
            return result;
        }