GtkSharp/generator/Parser.cs
Mike Kestner 30e653825c This is an enormous commit of stuff that I've been working on for several
weeks.  I'll be posting an update to gtk-sharp-list in a bit to describe my
latest psychosis.

svn path=/trunk/gtk-sharp/; revision=1797
2002-01-04 02:02:28 +00:00

103 lines
1.7 KiB
C#

// GtkSharp.Parser.cs - The XML Parsing engine.
//
// Author: Mike Kestner <mkestner@speakeasy.net>
//
// (c) 2001 Mike Kestner
namespace GtkSharp {
using System;
using System.Collections;
using System.Xml;
public class Parser {
private XmlDocument doc;
private Hashtable types;
public Parser (String filename)
{
doc = new XmlDocument ();
try {
doc.Load (filename);
} catch (XmlException e) {
Console.WriteLine ("Invalid XML file.");
Console.WriteLine (e.ToString());
}
}
public Hashtable Types {
get
{
if (types != null) return types;
XmlElement root = doc.DocumentElement;
if ((root == null) || !root.HasChildNodes) {
Console.WriteLine ("No Namespaces found.");
return null;
}
types = new Hashtable ();
foreach (XmlNode ns in root.ChildNodes) {
if (ns.Name != "namespace") {
continue;
}
XmlElement elem = (XmlElement) ns;
ParseNamespace (elem);
}
return types;
}
}
private void ParseNamespace (XmlElement ns)
{
String ns_name = ns.GetAttribute ("name");
foreach (XmlNode def in ns.ChildNodes) {
if (def.NodeType != XmlNodeType.Element) {
continue;
}
XmlElement elem = (XmlElement) def;
switch (def.Name) {
case "alias":
break;
case "callback":
break;
case "enum":
IGeneratable gen = new EnumGen (ns_name, elem);
types [gen.CName] = gen;
break;
case "object":
break;
case "struct":
break;
default:
Console.WriteLine ("Unexpected node.");
break;
}
}
}
}
}