Beispiel #1
0
 void DumpGroup(GroupDefinition gd, int indent)
 {
     Console.WriteLine("{0}{1}", new String(' ', indent), gd.ToString());
     foreach (GroupDefinition gd2 in gd.ChildGroups)
     {
         DumpGroup(gd2, indent + 1);
     }
 }
Beispiel #2
0
        void Run(string[] args)
        {
            if (args.Length < 1)
            {
                Usage("Invalid number of parameters");
            }

            Stack           context = new Stack();
            GroupDefinition groupZero = new GroupDefinition();
            GroupDefinition group, current;
            XmlReader       reader = null;
            string          outfile = null, infile = null;
            string          a;

            for (int i = 0; i < args.Length; i++)
            {
                a = args [i];
                if (a [0] == '-' && a.Length > 1)
                {
                    a = a.Substring(1).Trim();

                    switch (a.ToLower())
                    {
                    case "o":
                    case "output":
                    case "-output":
                        i++;
                        if (i > args.Length)
                        {
                            Usage("Missing output file name");
                        }
                        outfile = args [i];
                        break;

                    case "h":
                    case "help":
                    case "-help":
                        Usage(null);
                        break;

                    default:
                        Usage("Unknown command line option: '{0}'", a);
                        break;
                    }
                }
                else if (infile == null)
                {
                    infile = args [i];
                }
            }

            if (infile == null)
            {
                Usage("Missing input file on the command line.");
            }

            try {
                XmlNodeType nodeType;
                int         level   = 1;
                bool        ingroup = false;

                reader = new XmlTextReader(infile);
                while (reader.Read())
                {
                    nodeType = reader.NodeType;
                    if (nodeType != XmlNodeType.Element && nodeType != XmlNodeType.EndElement)
                    {
                        continue;
                    }

                    current = context.Count > 0 ? context.Peek() as GroupDefinition : null;
                    if (ingroup && reader.LocalName == "except")
                    {
                        if (current == null)
                        {
                            throw new ApplicationException("Inside a group but there is no group on the stack");
                        }

                        current.AddExcept(reader);
                        continue;
                    }

                    if (reader.LocalName != "group")
                    {
                        continue;
                    }

                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (current == null)
                        {
                            throw new ApplicationException("Found group end, but no current group on stack");
                        }
                        context.Pop();
                        if (context.Count == 0)
                        {
                            groupZero.ChildGroups.Add(current);
                            current.GroupId = groupZero.ChildGroups.Count;
                        }
                        level--;
                        ingroup = false;
                        continue;
                    }

                    group       = new GroupDefinition(reader);
                    group.Level = level++;

                    if (current != null)
                    {
                        current.ChildGroups.Add(group);
                        group.GroupId = current.ChildGroups.Count;
                    }

                    context.Push(group);
                    ingroup = true;
                }
            } catch (Exception) {
                throw;
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            CodeCompileUnit unit = groupZero.GenerateCode();

            if (unit == null)
            {
                Environment.Exit(1);
            }

            CodeDomProvider provider = new CSharpCodeProvider();
            ICodeGenerator  gen      = provider.CreateGenerator();

            TextWriter tw;

            if (outfile == null)
            {
                tw = Console.Out;
            }
            else
            {
                tw = new IndentedTextWriter(new StreamWriter(outfile, false), "\t");
            }
            gen.GenerateCodeFromCompileUnit(unit, tw, new CodeGeneratorOptions());
            if (outfile != null)
            {
                tw.Close();
            }
        }
Beispiel #3
0
		void Run (string[] args)
		{
			if (args.Length < 1)
				Usage ("Invalid number of parameters");
      
			Stack context = new Stack ();
			GroupDefinition groupZero = new GroupDefinition ();
			GroupDefinition group, current;
			XmlReader reader = null;
			string outfile = null, infile = null;
			string a;
      
			for (int i = 0; i < args.Length; i++) {
				a = args [i];
				if (a [0] == '-' && a.Length > 1) {
					a = a.Substring (1).Trim ();
	  
					switch (a.ToLower ()) {
						case "o":
						case "output":
						case "-output":
							i++;
							if (i > args.Length)
								Usage ("Missing output file name");
							outfile = args [i];
							break;

						case "h":
						case "help":
						case "-help":
							Usage (null);
							break;
	      
						default:
							Usage ("Unknown command line option: '{0}'", a);
							break;
					}
				} else if (infile == null)
					infile = args [i];
			}

			if (infile == null)
				Usage ("Missing input file on the command line.");
      
			try {
				XmlNodeType nodeType;
				int level = 1;
				bool ingroup = false;
	
				reader = new XmlTextReader (infile);
				while (reader.Read ()) {
					nodeType = reader.NodeType;
					if (nodeType != XmlNodeType.Element && nodeType != XmlNodeType.EndElement)
						continue;

					current = context.Count > 0 ? context.Peek () as GroupDefinition : null;
					if (ingroup && reader.LocalName == "except") {
						if (current == null)
							throw new ApplicationException ("Inside a group but there is no group on the stack");

						current.AddExcept (reader);
						continue;
					}
	    
					if (reader.LocalName != "group")
						continue;
	    
					if (reader.NodeType == XmlNodeType.EndElement) {
						if (current == null)
							throw new ApplicationException ("Found group end, but no current group on stack");
						context.Pop ();
						if (context.Count == 0) {
							groupZero.ChildGroups.Add (current);
							current.GroupId = groupZero.ChildGroups.Count;
						}
						level--;
						ingroup = false;
						continue;
					}
	    
					group = new GroupDefinition (reader);
					group.Level = level++;
	    
					if (current != null) {
						current.ChildGroups.Add (group);
						group.GroupId = current.ChildGroups.Count;
					}
	    
					context.Push (group);
					ingroup = true;
				}
			} catch (Exception) {
				throw;
			} finally {
				if (reader != null)
					reader.Close();
			}

			CodeCompileUnit unit = groupZero.GenerateCode ();
			if (unit == null)
				Environment.Exit (1);
      
			CodeDomProvider provider = new CSharpCodeProvider ();
			ICodeGenerator gen = provider.CreateGenerator ();

			TextWriter tw;
			if (outfile == null)
				tw = Console.Out;
			else
				tw = new IndentedTextWriter (new StreamWriter (outfile, false), "\t");
			gen.GenerateCodeFromCompileUnit (unit, tw, new CodeGeneratorOptions ());
			if (outfile != null)
				tw.Close ();
		}
Beispiel #4
0
		void DumpGroup (GroupDefinition gd, int indent)
		{
			Console.WriteLine ("{0}{1}", new String (' ', indent), gd.ToString ());
			foreach (GroupDefinition gd2 in gd.ChildGroups)
				DumpGroup (gd2, indent + 1);
		}