2002-01-05 12:45:55 +00:00
|
|
|
// GtkSharp.Generation.Parser.cs - The XML Parsing engine.
|
2002-01-04 02:02:28 +00:00
|
|
|
//
|
|
|
|
// Author: Mike Kestner <mkestner@speakeasy.net>
|
|
|
|
//
|
|
|
|
// (c) 2001 Mike Kestner
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
namespace GtkSharp.Generation {
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
public class Parser {
|
|
|
|
|
|
|
|
private XmlDocument doc;
|
|
|
|
|
|
|
|
public Parser (String filename)
|
|
|
|
{
|
|
|
|
doc = new XmlDocument ();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
doc.Load (filename);
|
|
|
|
|
|
|
|
} catch (XmlException e) {
|
|
|
|
|
|
|
|
Console.WriteLine ("Invalid XML file.");
|
|
|
|
Console.WriteLine (e.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-05-23 23:43:25 +00:00
|
|
|
public void Parse ()
|
2002-01-05 12:45:55 +00:00
|
|
|
{
|
|
|
|
XmlElement root = doc.DocumentElement;
|
2002-01-04 02:02:28 +00:00
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
if ((root == null) || !root.HasChildNodes) {
|
2002-01-04 02:02:28 +00:00
|
|
|
Console.WriteLine ("No Namespaces found.");
|
2002-05-23 23:43:25 +00:00
|
|
|
return;
|
2002-01-05 12:45:55 +00:00
|
|
|
}
|
2002-01-04 02:02:28 +00:00
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
foreach (XmlNode ns in root.ChildNodes) {
|
|
|
|
if (ns.Name != "namespace") {
|
|
|
|
continue;
|
2002-01-04 02:02:28 +00:00
|
|
|
}
|
|
|
|
|
2002-01-05 12:45:55 +00:00
|
|
|
XmlElement elem = (XmlElement) ns;
|
|
|
|
ParseNamespace (elem);
|
2002-01-04 02:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2002-01-05 12:45:55 +00:00
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
switch (def.Name) {
|
|
|
|
|
|
|
|
case "alias":
|
2002-05-26 16:23:40 +00:00
|
|
|
string aname = elem.GetAttribute("cname");
|
|
|
|
string atype = elem.GetAttribute("type");
|
|
|
|
if ((aname == "") || (atype == ""))
|
|
|
|
continue;
|
|
|
|
SymbolTable.AddAlias (aname, atype);
|
2002-01-04 02:02:28 +00:00
|
|
|
break;
|
2002-01-17 00:26:46 +00:00
|
|
|
|
|
|
|
case "boxed":
|
2002-06-21 20:25:43 +00:00
|
|
|
SymbolTable.AddType (new BoxedGen (ns, elem));
|
2002-01-17 00:26:46 +00:00
|
|
|
break;
|
2002-01-04 02:02:28 +00:00
|
|
|
|
|
|
|
case "callback":
|
2002-06-21 20:25:43 +00:00
|
|
|
SymbolTable.AddType (new CallbackGen (ns, elem));
|
2002-01-04 02:02:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "enum":
|
2002-06-21 20:25:43 +00:00
|
|
|
SymbolTable.AddType (new EnumGen (ns, elem));
|
2002-01-04 02:02:28 +00:00
|
|
|
break;
|
|
|
|
|
2002-01-07 23:30:01 +00:00
|
|
|
case "interface":
|
2002-06-21 20:25:43 +00:00
|
|
|
SymbolTable.AddType (new InterfaceGen (ns, elem));
|
2002-01-07 23:30:01 +00:00
|
|
|
break;
|
|
|
|
|
2002-01-04 02:02:28 +00:00
|
|
|
case "object":
|
2002-06-21 20:25:43 +00:00
|
|
|
SymbolTable.AddType (new ObjectGen (ns, elem));
|
2002-01-04 02:02:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "struct":
|
2002-06-21 20:25:43 +00:00
|
|
|
SymbolTable.AddType (new StructGen (ns, elem));
|
2002-01-04 02:02:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2002-03-24 17:04:25 +00:00
|
|
|
Console.WriteLine ("Unexpected node named " + def.Name);
|
2002-01-04 02:02:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|