Example #1
0
        public string Generate(PairGroup pg)
        {
            Generator g = new Generator();

            g.generateSwitch(
                (Pair[])pg.Pairs.ToArray(
                    typeof(Pair)), "0");
            return(g.P.ToString());
        }
Example #2
0
        public ArrayList Read(string fileName) {
            ArrayList pairGroups = new ArrayList();

			string content = string.Empty;
			using (StreamReader sr = new StreamReader(fileName)) {
				content = sr.ReadToEnd();
			}
			
			foreach (Match match in RegExpRegion.Matches(content)) {				
				PairGroup pg = new PairGroup();
				pg.Type = match.Groups[1].Value;
			
				foreach (Match mPair in RegExpPair.Matches(match.Groups[2].Value)) {
					string id = mPair.Groups[1].Value;
                    Pair pair = new Pair (id, id.Substring (3));
                    switch (pair.Value) {
                        case "STAR": pair.Value = "$*"; break;
                        case "UNDERSCORE": pair.Value = "$_"; break;
                        case "AMPERSAND": pair.Value = "$&"; break;
                        case "PLUS": pair.Value = "$+"; break;
                        case "BACKQUOTE": pair.Value = "$`"; break;
                        case "QUOTE": pair.Value = "$'"; break;
                        case "DOLLAR_0": pair.Value = "$0"; break;
                        case "DOLLAR_1": pair.Value = "$1"; break;
                        case "DOLLAR_2": pair.Value = "$2"; break;
                        case "DOLLAR_3": pair.Value = "$3"; break;
                        case "DOLLAR_4": pair.Value = "$4"; break;
                        case "DOLLAR_5": pair.Value = "$5"; break;
                        case "DOLLAR_6": pair.Value = "$6"; break;
                        case "DOLLAR_7": pair.Value = "$7"; break;
                        case "DOLLAR_8": pair.Value = "$8"; break;
                        case "DOLLAR_9": pair.Value = "$9"; break;
                    }
                        
					pg.Pairs.Add(pair);					
				}


				pairGroups.Add(pg);

				if (pg.Pairs.Count == 0) {
					Console.WriteLine("WARN: Found PairGroup ("  + pg.Type + ") but no pairs.");
				}
			}

			return pairGroups;
        }
Example #3
0
		public string Generate(PairGroup pg) {
			Generator g = new Generator();
			g.generateSwitch(
				(Pair[])pg.Pairs.ToArray(
				typeof(Pair)), "0");
			return g.P.ToString();	
		}
Example #4
0
        public bool Write(string fileName, ArrayList pairGroups)
        {
            if (pairGroups.Count == 0)
            {
                return(false);
            }

            Console.Write(Path.GetFileName(fileName));
            Console.Write("\t" + pairGroups.Count);

            string tmpFileName = Path.ChangeExtension(fileName, "bak." + DateTime.Now.Ticks.ToString());

            using (StreamWriter sw = new StreamWriter(tmpFileName)) {
                string generated = string.Empty;
                using (StreamReader sr = new StreamReader(fileName)) {
                    do
                    {
                        string line = sr.ReadLine();
                        if (line == null)
                        {
                            break;
                        }

                        if (generated != string.Empty)
                        {
                            if (line.IndexOf("#endregion") != -1)
                            {
                                sw.WriteLine(generated);
                                sw.WriteLine(line);
                                generated = string.Empty;
                            }
                            continue;
                        }

                        int idx;

                        idx = line.IndexOf("#region Generated PrototypeId Switch");
                        if (idx != -1)
                        {
                            PairGroup pg = GetPairGroup(pairGroups, "PrototypeIds");
                            generated = Generate(pg);
                            sw.WriteLine(line);
                            pairGroups.Remove(pg);
                            continue;
                        }

                        idx = line.IndexOf("#region Generated InstanceId Switch");
                        if (idx != -1)
                        {
                            PairGroup pg = GetPairGroup(pairGroups, "InstanceIds");
                            generated = Generate(pg);
                            sw.WriteLine(line);
                            pairGroups.Remove(pg);
                            continue;
                        }

                        idx = line.IndexOf("#region Generated Id Switch");
                        if (idx != -1)
                        {
                            PairGroup pg = GetPairGroup(pairGroups, "Ids");
                            generated = Generate(pg);
                            sw.WriteLine(line);
                            pairGroups.Remove(pg);
                            continue;
                        }

                        sw.WriteLine(line);
                    } while (true);
                }
            }

            File.Copy(tmpFileName, fileName, true);
            File.Delete(tmpFileName);

            Console.Write("\tUPDATED");
            Console.Write("\t" + pairGroups.Count);
            Console.WriteLine();

            return(false);
        }
        public ArrayList Read(string fileName)
        {
            ArrayList pairGroups = new ArrayList();

            string content = string.Empty;

            using (StreamReader sr = new StreamReader(fileName)) {
                content = sr.ReadToEnd();
            }

            foreach (Match match in RegExpRegion.Matches(content))
            {
                PairGroup pg = new PairGroup();
                pg.Type = match.Groups[1].Value;

                foreach (Match mPair in RegExpPair.Matches(match.Groups[2].Value))
                {
                    string id   = mPair.Groups[1].Value;
                    Pair   pair = new Pair(id, id.Substring(3));
                    switch (pair.Value)
                    {
                    case "STAR": pair.Value = "$*"; break;

                    case "UNDERSCORE": pair.Value = "$_"; break;

                    case "AMPERSAND": pair.Value = "$&"; break;

                    case "PLUS": pair.Value = "$+"; break;

                    case "BACKQUOTE": pair.Value = "$`"; break;

                    case "QUOTE": pair.Value = "$'"; break;

                    case "DOLLAR_0": pair.Value = "$0"; break;

                    case "DOLLAR_1": pair.Value = "$1"; break;

                    case "DOLLAR_2": pair.Value = "$2"; break;

                    case "DOLLAR_3": pair.Value = "$3"; break;

                    case "DOLLAR_4": pair.Value = "$4"; break;

                    case "DOLLAR_5": pair.Value = "$5"; break;

                    case "DOLLAR_6": pair.Value = "$6"; break;

                    case "DOLLAR_7": pair.Value = "$7"; break;

                    case "DOLLAR_8": pair.Value = "$8"; break;

                    case "DOLLAR_9": pair.Value = "$9"; break;
                    }

                    pg.Pairs.Add(pair);
                }


                pairGroups.Add(pg);

                if (pg.Pairs.Count == 0)
                {
                    Console.WriteLine("WARN: Found PairGroup (" + pg.Type + ") but no pairs.");
                }
            }

            return(pairGroups);
        }