Exemplo n.º 1
0
        public static ScriptMethod GetScriptMethod(string name, string code)
        {
            ScriptMethod method = new ScriptMethod(name, code);

            if (string.IsNullOrEmpty(code))
            {
                method.Type = methodType.None;
            }
            if (code.Contains("DECLARE"))
            {
                method.Type = methodType.Declaration;
                code        = code.Replace("DECLARE", "");
            }
            if (code.Contains("EVENT"))
            {
                method.Type = methodType.Event;
                code        = code.Replace("EVENT", "");
            }

            //var lines = code.Split(CODE_INFO.LineSeparator);
            //var lines = StringUtils.CustomSplit(code,CODE_INFO.LineSeparator,')');
            var lines = CODE_READER.GetScriptLines(code);

            foreach (var line in lines)
            {
                CODE_READER.CheckLanguageRoutines(line, 1);
                ScriptEvent e = ScriptEvent.GetEvent(line);
                if (e != null && e.Conditions.Count > 0)
                {
                    method.Events.Add(e);
                }
            }
            return(method);
        }
Exemplo n.º 2
0
        public void AnalyzeCode()
        {
            CODE_EXEC.Fields.Clear();
            var lines = CODE_READER.GetScriptLines(CurrentCode);

            foreach (var line in lines)
            {
                var lineCode = CodeTranslator.TranslateCode(line);
                CODE_READER.CheckLanguageRoutines(lineCode, 0);
            }
        }
Exemplo n.º 3
0
        public static string TranslateScript(string script)
        {
            script = script.Replace("\r\n", "");
            var lines = CODE_READER.GetScriptLines(script);
            int index = 0;

            foreach (var line in lines)
            {
                if (line.Contains("="))
                {
                    lines[index] = TranslateCode(lines[index]);
                }
                index++;
            }
            return(script);
        }
Exemplo n.º 4
0
        public static object[] GetArgs(string code, out conditionType condition)
        {
            List <object> args = new List <object>();

            condition = conditionType.None;
            if (code.Length > 0 && code[code.Length - 1] != '?')
            {
                var ls = code.Split('?');
                code = ls[0];
            }
            var l = code.Split(' ');

            //if(code.Contains(":")){code = code.Replace(":","");}
            if (code.Contains("When") && l.Length >= 4)
            {
                string first  = l[1];
                string second = l[3];
                object obj0   = CODE_READER.FindValue(first);
                object obj1   = CODE_READER.FindValue(second);
                args.Add(obj0);
                args.Add(obj1);
                string lc = l[2];
                if (lc == "equals")
                {
                    condition = conditionType.Equal;
                }
                if (lc == "lessThan")
                {
                    condition = conditionType.LessThan;
                }
                if (lc == "largerThan")
                {
                    condition = conditionType.LargerThan;
                }
                if (lc == "notEqual")
                {
                    condition = conditionType.NotEqual;
                }
            }
            return(args.ToArray());
        }
Exemplo n.º 5
0
        public static ScriptLoopEventHandler GetLoopHandler(string code)
        {
            ScriptLoopEventHandler loop = new ScriptLoopEventHandler();
            var inside = StringUtils.GetInside(code, "(", ")");

            if (inside.Contains("infinity") || inside.Contains("Infinity"))
            {
                loop.LoopType     = loopType.Infinity;
                loop.CurrentIndex = -1;
                loop.MaxIndex     = -1;
            }
            else
            {
                if (inside.Contains(" ") && !inside.Contains("stop loop"))
                {
                    loop.LoopType = loopType.Condition;
                    var    l    = inside.Split(' ');
                    object arg0 = CODE_READER.FindValue(l[0]);
                    object arg1 = CODE_READER.FindValue(l[2]);
                    loop.Cond0 = arg0;
                    loop.Cond1 = arg1;
                }
                else
                {
                    loop.LoopType = loopType.Iteration;
                    object arg = CODE_READER.FindValue(inside);
                    if (!(arg is int) && arg is string)
                    {
                        arg = StringUtils.FilterInteger((string)arg, true);
                    }
                    if (arg is int)
                    {
                        loop.MaxIndex = (int)arg;
                    }
                }
            }
            return(loop);
        }