diff options
author | Jasper St. Pierre <jstpierre@mecheye.net> | 2012-08-28 20:45:22 -0300 |
---|---|---|
committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2012-08-29 00:33:56 -0300 |
commit | b821d848a58c40bfe26262352cd66aa6eeac5d4a (patch) | |
tree | 8100c2dcce0022aec702c70634fe04787cc33fd9 /giscanner | |
parent | 74616c2a0e30da1a5c4f912807f6ab181e639f96 (diff) | |
download | gobject-introspection-b821d848a58c40bfe26262352cd66aa6eeac5d4a.tar.gz |
mallardwriter: Use a more generic system for language formatting
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/mallardwriter.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/giscanner/mallardwriter.py b/giscanner/mallardwriter.py index 585713a2..876bd872 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] |