diff options
author | Johan Dahlin <johan@gnome.org> | 2010-09-16 00:37:49 -0300 |
---|---|---|
committer | Johan Dahlin <johan@gnome.org> | 2010-09-24 16:06:53 -0300 |
commit | 7cc31be7753b124b7f17febbbe0607765b426fa0 (patch) | |
tree | 1ad650110b5862701c653882fe2701cc937663b8 /giscanner/annotationparser.py | |
parent | 2aadc9201bf320820a02a789aaf9b1681fd453d5 (diff) | |
download | gobject-introspection-7cc31be7753b124b7f17febbbe0607765b426fa0.tar.gz |
Add an annotation tool
Diffstat (limited to 'giscanner/annotationparser.py')
-rw-r--r-- | giscanner/annotationparser.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index f2bc1d4b..282ea550 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -106,6 +106,9 @@ class DocBlock(object): self.params = [] self.position = None + def __cmp__(self, other): + return cmp(self.name, other.name) + def __repr__(self): return '<DocBlock %r %r>' % (self.name, self.options) @@ -116,6 +119,29 @@ class DocBlock(object): def get(self, name): return self.tags.get(name) + def to_gtk_doc(self): + lines = [self.name + ':'] + tags = [] + for name, tag in self.tags.iteritems(): + if name in self.params: + lines.append(tag.to_gtk_doc_param()) + else: + tags.append(tag) + + lines.append('') + for l in self.comment.split('\n'): + lines.append(l) + if tags: + lines.append('') + for tag in tags: + lines.append(tag.to_gtk_doc_tag()) + + comment = '/**\n' + for line in lines: + comment += ' * %s\n' % (line, ) + comment += ' */\n' + return comment + def validate(self): for tag in self.tags.values(): tag.validate() @@ -169,6 +195,32 @@ class DocTag(object): self.position = position self.options.position = position + def _get_gtk_doc_value(self): + def serialize_one(option, value, fmt, fmt2): + if value: + if type(value) != str: + value = ' '.join((serialize_one(k, v, '%s=%s', '%s') + for k,v in value.all().iteritems())) + return fmt % (option, value) + else: + return fmt2 % (option, ) + annotations = [] + for option, value in self.options.iteritems(): + annotations.append( + serialize_one(option, value, '(%s %s)', '(%s)')) + if annotations: + return ' '.join(annotations) + ': ' + else: + return self.value + + def to_gtk_doc_param(self): + return '@%s: %s%s' % (self.name, self._get_gtk_doc_value(), self.comment) + + def to_gtk_doc_tag(self): + return '%s: %s%s' % (self.name.capitalize(), + self._get_gtk_doc_value(), + self.comment or '') + def validate(self): for option in self.options: value = self.options[option] |