Exemplo n.º 1
0
        public object ExecLine(object targetObject, string line)
        {
            if (string.IsNullOrEmpty(line))
            {
                throw new EmptyCommandLineException();
            }

            string functionName = string.Empty;
            string args         = string.Empty;
            var    words        = line.Trim().Split(' ').ToList();
            var    pattern      = @"(\w*)\(([\w|\,|\s]*)\)";
            Match  match        = Regex.Match(line, pattern);

            if (match.Success)
            {
                int captureCtr = 0;
                for (int ctr = 1; ctr <= match.Groups.Count - 1; ctr++)
                {
                    foreach (Capture capture in match.Groups[ctr].Captures)
                    {
                        if (captureCtr == 0)
                        {
                            functionName = capture.Value;
                        }
                        else
                        {
                            if (capture.Value.Length > 0)
                            {
                                args = capture.Value;
                            }
                        }
                        captureCtr += 1;
                    }
                }
            }
            else
            {
                throw new LineSyntaxErrorException(line);
            }

            return(functionExecutor.ExecFunction(targetObject, functionName, args.Split(',').ToList().Where(a => a.Length > 0).ToArray()));
        }