Esempio n. 1
0
        public static ArgsTypes[] GetArgsTypes(string path, Group[] groups)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("File not found.");
            }

            string[] argsSTR = File.ReadAllLines(path);

            if (argsSTR.Length <= 1)
            {
                throw new Exception("File doesn't have any arg type.");
            }

            ArgsTypes[] argsTypes = new ArgsTypes[argsSTR.Length - 1];
            string[]    args;
            int         b = 0;

            for (int i = 1; i < argsSTR.Length; i++)
            {
                args = argsSTR[i].Split(';');

                if (args.Length != 6)
                {
                    throw new Exception("Invalid Command at line: " + i);
                }

                if (args[3] == "var")
                {
                    b = -1;
                }
                else if (!int.TryParse(args[3], out b))
                {
                    throw new Exception("Invalid Command at line: " + i);
                }

                argsTypes[i - 1] = new ArgsTypes
                {
                    Name    = args[0],
                    Prefix  = args[1].ToLower(),
                    Postfix = args[2].ToLower(),
                    Bytes   = b,
                    Type    = args[4],
                    Group   = Group.FindGroup(groups, args[5])
                };
                argsTypes[i - 1].buildRegEX();
            }

            return(argsTypes);
        }
Esempio n. 2
0
 public Code(string _ArgsTypes, string _Commands, string _Groups)
 {
     autoCompleteTexts = new List <string>();
     groups            = Group.GetGroups(_Groups);
     argsTypes         = ArgsTypes.GetArgsTypes(_ArgsTypes, groups);
     commands          = Command.GetCommands(_Commands, argsTypes, groups);
     labels            = new Label[4];
     labels[0]         = new NormalLabel(groups, "Label");
     labels[1]         = new SubLabel(groups, "Special Label");
     labels[2]         = new PlusLabel(groups, "Special Label");
     labels[3]         = new MinusLabel(groups, "Special Label");
     defines           = new Dictionary <string, Define>();
     errors            = new Dictionary <int, List <Error> >();
     DefaultGroup      = Group.Default;
     ErrorGroup        = Group.FindGroup(groups, "Error");
     CommentGroup      = Group.FindGroup(groups, "Comment");
     DefineGroup       = Group.FindGroup(groups, "Define");
     DefineArgsGroup   = Group.FindGroup(groups, "Define Arg");
 }
Esempio n. 3
0
                                                      Dictionary <string, Command[]> > > GetCommands(string path,
                                                                                                     ArgsTypes[] argsTypes, Group[] groups)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("File not found.");
            }

            string[] commandsSTR = File.ReadAllLines(path);

            if (commandsSTR.Length <= 1)
            {
                throw new Exception("File doesn't have any command.");
            }

            Command[] commands = new Command[commandsSTR.Length - 1];
            string[]  cmd;
            int       nums = 0;

            ArgsTypes[] newargs;

            for (int i = 1; i < commandsSTR.Length; i++)
            {
                cmd = commandsSTR[i].Split(';');
                if (cmd.Length <= 1)
                {
                    throw new Exception("Invalid Command at line: " + i);
                }

                if (!int.TryParse(cmd[1].Replace(" ", "").Replace("   ", ""),
                                  out nums))
                {
                    throw new Exception("Invalid Command at line: " + i);
                }

                if (nums > cmd.Length - 3)
                {
                    throw new Exception("Invalid Command at line: " + i);
                }
                newargs = null;
                if (nums > 0)
                {
                    newargs = new ArgsTypes[nums];
                    for (int j = 0; j < nums; j++)
                    {
                        newargs[j] = ArgsTypes.Exists(cmd[j + 3], argsTypes);
                        if (newargs[j] == null)
                        {
                            throw new Exception("Invalid Command at line: " + i);
                        }
                    }
                }

                commands[i - 1] = new Command(cmd[0].ToLower(), newargs,
                                              Group.FindGroup(groups, cmd[2]));
                if (commands[i - 1].Args != null && commands[i - 1].Args.Length > 0)
                {
                    commands[i - 1].Prefix = commands[i - 1].Args[0].Prefix;
                    commands[i - 1].Sufix  = commands[i - 1].Args[commands[i - 1].Args.Length - 1].Postfix;

                    string pref;
                    pref = commands[i - 1].Prefix.Replace(",", ", *").Replace("[", @"\[").Replace("]", @"\]");
                    string postf;
                    postf = commands[i - 1].Sufix.Replace(",", ", *").Replace("[", @"\[").Replace("]", @"\]");
                    pref  = pref.Replace(".", @"\.").Replace("+", @"\+");
                    postf = postf.Replace(".", @"\.").Replace("+", @"\+");
                    pref  = pref.Replace("(", @"\(").Replace(")", @"\)" + numPostMod);
                    postf = postf.Replace("(", @"\(").Replace(")", @"\)" + numPostMod);
                    commands[i - 1].Prefix = "^" + pref;
                    commands[i - 1].Sufix  = postf + "$";
                }
                if (commands[i - 1].Prefix == null || commands[i - 1].Prefix == "^")
                {
                    commands[i - 1].Prefix = "NULL";
                }
                if (commands[i - 1].Sufix == null || commands[i - 1].Sufix == "$")
                {
                    commands[i - 1].Sufix = "NULL";
                }
            }

            Dictionary <string, Dictionary <string, Dictionary <string, List <Command> > > > dic =
                new Dictionary <string, Dictionary <string, Dictionary <string, List <Command> > > >();

            foreach (Command c in commands)
            {
                if (!dic.ContainsKey(c.Name))
                {
                    dic.Add(c.Name, new Dictionary <string, Dictionary <string, List <Command> > >());
                }
                if (!dic[c.Name].ContainsKey(c.Prefix))
                {
                    dic[c.Name].Add(c.Prefix, new Dictionary <string, List <Command> >());
                }
                if (!dic[c.Name][c.Prefix].ContainsKey(c.Sufix))
                {
                    dic[c.Name][c.Prefix].Add(c.Sufix, new List <Command>());
                }
                dic[c.Name][c.Prefix][c.Sufix].Add(c);
            }

            Dictionary <string, Dictionary <string,
                                            Dictionary <string, Command[]> > > arrDic = new Dictionary <string, Dictionary <string,
                                                                                                                            Dictionary <string, Command[]> > >();

            foreach (string s in dic.Keys)
            {
                arrDic.Add(s, new Dictionary <string, Dictionary <string, Command[]> >());
                foreach (string s2 in dic[s].Keys)
                {
                    arrDic[s].Add(s2, new Dictionary <string, Command[]>());
                    foreach (string s3 in dic[s][s2].Keys)
                    {
                        arrDic[s][s2].Add(s3, dic[s][s2][s3].ToArray());
                    }
                }
            }

            return(arrDic);
        }