[gobject-introspection] mallardwriter: Use a more generic system for language formatting
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] mallardwriter: Use a more generic system for language formatting
- Date: Wed, 29 Aug 2012 06:16:22 +0000 (UTC)
commit b821d848a58c40bfe26262352cd66aa6eeac5d4a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Aug 28 20:45:22 2012 -0300
mallardwriter: Use a more generic system for language formatting
giscanner/mallardwriter.py | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py
index 585713a..876bd87 100644
--- a/giscanner/mallardwriter.py
+++ b/giscanner/mallardwriter.py
@@ -127,6 +127,8 @@ class MallardFormatter(object):
return parent_chain
class MallardFormatterC(MallardFormatter):
+ language = "C"
+
def format_type(self, type_):
if isinstance(type_, ast.Array):
try:
@@ -139,6 +141,8 @@ class MallardFormatterC(MallardFormatter):
return type_.target_fundamental
class MallardFormatterPython(MallardFormatter):
+ language = "Python"
+
def format_type(self, type_):
if isinstance(type_, ast.Array):
return '[' + self.format_type(type_.element_type) + ']'
@@ -157,17 +161,22 @@ class MallardFormatterPython(MallardFormatter):
doc = doc.replace('%FALSE', 'False')
return doc
+LANGUAGES = {
+ "c": MallardFormatterC,
+ "python": MallardFormatterPython,
+}
+
class MallardWriter(object):
def __init__(self, transformer, language):
self._transformer = transformer
- self._language = language
- if self._language == 'C':
- self._formatter = MallardFormatterC(self._transformer)
- elif self._language == 'Python':
- self._formatter = MallardFormatterPython(self._transformer)
- else:
- raise SystemExit("Unsupported language: %s" % language)
+ try:
+ formatter_class = LANGUAGES[language.lower()]
+ except KeyError:
+ raise SystemExit("Unsupported language: %s" % (language,))
+
+ self._formatter = formatter_class(self._transformer)
+ self._language = self._formatter.language
def write(self, output):
nodes = [self._transformer.namespace]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]