Example #1
0
        static ParserFunction GetObjectFunction(string name, ParsingScript script)
        {
            if (script.CurrentClass != null && script.CurrentClass.Name == name)
            {
                script.Backward(name.Length + 1);
                return(new FunctionCreator());
            }
            if (script.ClassInstance != null &&
                (script.ClassInstance.PropertyExists(name) || script.ClassInstance.FunctionExists(name)))
            {
                name = script.ClassInstance.InstanceName + "." + name;
            }
            //int ind = name.LastIndexOf('.');
            int ind = name.IndexOf('.');

            if (ind <= 0)
            {
                return(null);
            }
            string baseName = name.Substring(0, ind);

            if (s_namespaces.ContainsKey(baseName))
            {
                int ind2 = name.IndexOf('.', ind + 1);
                if (ind2 > 0)
                {
                    ind      = ind2;
                    baseName = name.Substring(0, ind);
                }
            }

            string prop = name.Substring(ind + 1);

            ParserFunction pf = ParserFunction.GetFromNamespace(prop, baseName, script);

            if (pf != null)
            {
                return(pf);
            }

            pf = ParserFunction.GetVariable(baseName, script, true);
            if (pf == null || !(pf is GetVarFunction))
            {
                pf = ParserFunction.GetFunction(baseName, script);
                if (pf == null)
                {
                    pf = Utils.ExtractArrayElement(baseName);
                }
            }

            GetVarFunction varFunc = pf as GetVarFunction;

            if (varFunc == null)
            {
                return(null);
            }

            varFunc.PropertyName = prop;
            return(varFunc);
        }
Example #2
0
        static ParserFunction GetArrayFunction(string name, ParsingScript script, string action)
        {
            int arrayStart = name.IndexOf(Constants.START_ARRAY);

            if (arrayStart < 0)
            {
                return(null);
            }

            if (arrayStart == 0)
            {
                Variable arr = Utils.ProcessArrayMap(new ParsingScript(name));
                return(new GetVarFunction(arr));
            }

            string arrayName = name;

            int             delta        = 0;
            List <Variable> arrayIndices = Utils.GetArrayIndices(script, arrayName, delta, (string arr, int del) => { arrayName = arr; delta = del; });

            if (arrayIndices.Count == 0)
            {
                return(null);
            }

            ParserFunction pf      = ParserFunction.GetVariable(arrayName, script);
            GetVarFunction varFunc = pf as GetVarFunction;

            if (varFunc == null)
            {
                return(null);
            }

            // we temporarily backtrack for the processing
            script.Backward(name.Length - arrayStart - 1);
            script.Backward(action != null ? action.Length : 0);
            // delta shows us how manxy chars we need to advance forward in GetVarFunction()
            delta -= arrayName.Length;
            delta += action != null ? action.Length : 0;

            varFunc.Indices = arrayIndices;
            varFunc.Delta   = delta;
            return(varFunc);
        }
Example #3
0
        protected override Variable Evaluate(ParsingScript script)
        {
            script.MoveForwardIf(Constants.SPACE);
            if (!script.FromPrev(Constants.RETURN.Length).Contains(Constants.RETURN))
            {
                script.Backward();
            }
            Variable result = Utils.GetItem(script);

            // If we are in Return, we are done:
            script.SetDone();
            result.IsReturn = true;

            return(result);
        }
Example #4
0
        static bool StillCollecting(string item, char[] to, ParsingScript script,
                                    ref string action)
        {
            char prev = script.TryPrevPrev();
            char ch   = script.TryPrev();
            char next = script.TryCurrent();

            if (to.Contains(ch) || ch == Constants.START_ARG ||
                ch == Constants.START_GROUP ||
                next == Constants.EMPTY)
            {
                return(false);
            }

            // Case of a negative number, or a pointer, or starting with the closing bracket:
            if (item.Length == 0 &&
                ((ch == '-' && next != '-') || ch == '&' ||
                 ch == Constants.END_ARRAY ||
                 ch == Constants.END_ARG))
            {
                return(true);
            }

            // Case of a scientific notation 1.2e+5 or 1.2e-5 or 1e5:
            if (Char.ToUpper(prev) == 'E' &&
                (ch == '-' || ch == '+' || Char.IsDigit(ch)) &&
                item.Length > 1 && Char.IsDigit(item[item.Length - 2]))
            {
                return(true);
            }

            // Otherwise if it's an action (+, -, *, etc.) or a space
            // we're done collecting current token.
            if ((action = Utils.ValidAction(script.FromPrev())) != null ||
                (item.Length > 0 && ch == Constants.SPACE))
            {
                return(false);
            }

            if (ch == Constants.TERNARY_OPERATOR)
            {
                script.Backward();
                return(false);
            }
            return(true);
        }
Example #5
0
        protected override Variable Evaluate(ParsingScript script)
        {
            var labelName = Utils.GetToken(script, Constants.TOKEN_SEPARATION);

            Dictionary <string, int> labels;

            if (script.AllLabels == null || script.LabelToFile == null |
                !script.AllLabels.TryGetValue(script.FunctionName, out labels))
            {
                Utils.ThrowErrorMsg("Couldn't find labels in function [" + script.FunctionName + "].",
                                    script, m_name);
                return(Variable.EmptyInstance);
            }

            int gotoPointer;

            if (!labels.TryGetValue(labelName, out gotoPointer))
            {
                Utils.ThrowErrorMsg("Couldn't find label [" + labelName + "].",
                                    script, m_name);
                return(Variable.EmptyInstance);
            }

            string filename;

            if (script.LabelToFile.TryGetValue(labelName, out filename) &&
                filename != script.Filename && !string.IsNullOrWhiteSpace(filename))
            {
                var newScript = script.GetIncludeFileScript(filename);
                script.Filename = filename;
                script.String   = newScript.String;
            }

            if (!m_isGoto)
            {
                script.PointersBack.Add(script.Pointer);
            }

            script.Pointer = gotoPointer;
            if (string.IsNullOrWhiteSpace(script.FunctionName))
            {
                script.Backward();
            }

            return(Variable.EmptyInstance);
        }
Example #6
0
        static ParserFunction GetObjectFunction(string name, ParsingScript script)
        {
            if (script.CurrentClass != null && script.CurrentClass.Name == name)
            {
                script.Backward(name.Length + 1);
                return(new FunctionCreator());
            }
            if (script.ClassInstance != null &&
                (script.ClassInstance.PropertyExists(name) || script.ClassInstance.FunctionExists(name)))
            {
                name = script.ClassInstance.InstanceName + "." + name;
            }
            int ind = name.IndexOf(".");

            if (ind <= 0)
            {
                return(null);
            }
            string baseName = name.Substring(0, ind);
            string prop     = name.Substring(ind + 1);

            ParserFunction pf = ParserFunction.GetFunctionNamespace(prop, baseName, script);

            if (pf != null)
            {
                return(pf);
            }

            pf = ParserFunction.GetFunction(baseName, script);
            GetVarFunction varFunc = pf as GetVarFunction;

            if (varFunc == null)
            {
                return(null);
            }

            varFunc.PropertyName = prop;
            return(varFunc);
        }