diff options
author | Johan Dahlin <johan@gnome.org> | 2008-04-28 01:21:27 +0000 |
---|---|---|
committer | Johan Dahlin <johan@src.gnome.org> | 2008-04-28 01:21:27 +0000 |
commit | fd3faa5d62cdf5b4108d2cf103d03e0e88baa52f (patch) | |
tree | 6664ec8c50fab7b745258678df5f7cb40a16a44d /giscanner | |
parent | 1fdc97d62fd2c523db8a8053f7b6e9af598cde45 (diff) | |
download | gobject-introspection-fd3faa5d62cdf5b4108d2cf103d03e0e88baa52f.tar.gz |
Switch over to GIR as the default format. Add a simple GIDL parser. Update
2008-04-27 Johan Dahlin <johan@gnome.org>
* configure.ac:
* giscanner/Makefile.am:
* giscanner/girparser.py:
* giscanner/glibtransformer.py:
* tests/parser/Foo-expected.gidl:
* tests/parser/Foo-expected.gir:
* tests/parser/Makefile.am:
* tests/parser/utility-expected.gidl:
* tests/parser/utility-expected.gir:
* tools/g-ir-scanner:
Switch over to GIR as the default format. Add a simple GIDL
parser.
Update tests and fix simplify makefiles by depending
on GNU make extensions.
svn path=/trunk/; revision=237
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/Makefile.am | 1 | ||||
-rw-r--r-- | giscanner/girparser.py | 57 | ||||
-rw-r--r-- | giscanner/glibtransformer.py | 10 |
3 files changed, 66 insertions, 2 deletions
diff --git a/giscanner/Makefile.am b/giscanner/Makefile.am index 8dfa3a8b..4b08a07f 100644 --- a/giscanner/Makefile.am +++ b/giscanner/Makefile.am @@ -32,6 +32,7 @@ pkgpyexec_PYTHON = \ gidlast.py \ gidlparser.py \ gidlwriter.py \ + girparser.py \ girwriter.py \ glibtransformer.py \ odict.py \ diff --git a/giscanner/girparser.py b/giscanner/girparser.py new file mode 100644 index 00000000..ef0c4a8c --- /dev/null +++ b/giscanner/girparser.py @@ -0,0 +1,57 @@ +# -*- Mode: Python -*- +# GObject-Introspection - a framework for introspecting GObject libraries +# Copyright (C) 2008 Johan Dahlin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +from xml.etree.ElementTree import parse + +from .glibast import GLibObject + +CORE = "{http://www.gtk.org/introspection/core/1.0}" +GLIB = "{http://www.gtk.org/introspection/glib/1.0}" + + +class GIRParser(object): + def __init__(self, filename): + self._nodes = [] + self._namespace_name = None + + tree = parse(filename) + self._parse_api(tree.getroot()) + + def _parse_api(self, root): + assert root.tag == '%srepository' % (CORE,), root + ns = root.find('%snamespace' % (CORE,)) + self._namespace_name = ns.attrib['name'] + for child in ns.getchildren(): + if child.tag == '%sclass' % (CORE,): + self._parse_object(child) + else: + print 'PARSER: Unhandled %s' % (child.tag,) + + def _parse_object(self, node): + gobj = GLibObject(node.attrib['name'], + node.attrib.get('parent'), + node.attrib['%stype-name' % (GLIB,)], + node.attrib['%sget-type' % (GLIB,)]) + self._nodes.append(gobj) + + def get_namespace_name(self): + return self._namespace_name + + def get_nodes(self): + return self._nodes diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py index 3812939a..47ebe2dc 100644 --- a/giscanner/glibtransformer.py +++ b/giscanner/glibtransformer.py @@ -82,8 +82,14 @@ class GLibTransformer(object): self._pair_class_struct(node) def register_include(self, filename): - from .gidlparser import GIDLParser - parser = GIDLParser(filename) + if filename.endswith('.gir'): + from .girparser import GIRParser + parser = GIRParser(filename) + elif filename.endswith('.gidl'): + from .gidlparser import GIDLParser + parser = GIDLParser(filename) + else: + raise NotImplementedError(filename) nsname = parser.get_namespace_name() for node in parser.get_nodes(): self._type_names[node.type_name] = (nsname, node) |