diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-07-25 17:22:21 +0200 |
---|---|---|
committer | Dieter Verfaillie <dieterv@optionexplicit.be> | 2013-10-08 20:55:43 +0200 |
commit | 839e4f10a6b291a261c200484ff05ec44a31d93e (patch) | |
tree | 5f4751874fd3f8c98d7dc3ae8d04e4d7e3a20a66 /giscanner | |
parent | 1fdb3fc24bec54ccaef132c415d365db4cbd16d9 (diff) | |
download | gobject-introspection-839e4f10a6b291a261c200484ff05ec44a31d93e.tar.gz |
giscanner: extract tag values
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/annotationparser.py | 63 | ||||
-rw-r--r-- | giscanner/maintransformer.py | 26 |
2 files changed, 62 insertions, 27 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index 1828c743..26e001e1 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -459,6 +459,36 @@ MULTILINE_ANNOTATION_CONTINUATION_RE = re.compile( ''', re.UNICODE | re.VERBOSE) +# Pattern matching value and description fields for TAG_DEPRECATED & TAG_SINCE tags. +TAG_VALUE_VERSION_RE = re.compile( + r''' + ^ # start + \s* # 0 or more whitespace characters + (?P<value>([0-9\.])*) # value + \s* # 0 or more whitespace characters + (?P<delimiter>:?) # delimiter + \s* # 0 or more whitespace characters + (?P<description>.*?) # description + \s* # 0 or more whitespace characters + $ # end + ''', + re.UNICODE | re.VERBOSE) + +# Pattern matching value and description fields for TAG_STABILITY tags. +TAG_VALUE_STABILITY_RE = re.compile( + r''' + ^ # start + \s* # 0 or more whitespace characters + (?P<value>(stable|unstable|private|internal)?) # value + \s* # 0 or more whitespace characters + (?P<delimiter>:?) # delimiter + \s* # 0 or more whitespace characters + (?P<description>.*?) # description + \s* # 0 or more whitespace characters + $ # end + ''', + re.UNICODE | re.VERBOSE | re.IGNORECASE) + class DocOption(object): @@ -645,13 +675,19 @@ class GtkDocTag(object): return fmt % (option, value) else: return fmt2 % (option, ) + serialized = '' annotations = [] for ann_name, options in self.annotations.items(): annotations.append(serialize_one(ann_name, options, '(%s %s)', '(%s)')) if annotations: - return ' '.join(annotations) + ': ' - else: - return self.value + serialized += ' '.join(annotations) + if self.value and annotations: + serialized += ': ' + if self.value: + serialized += self.value + if self.description and (annotations or self.value): + serialized += ': ' + return serialized def to_gtk_doc_param(self): return '@%s: %s%s' % (self.name, self._get_gtk_doc_value(), self.description) @@ -1185,7 +1221,7 @@ class GtkDocCommentBlockParser(object): tag = GtkDocTag(tag_name.lower()) tag.position = position - tag.value = tag_description + if tag_annotations: if tag_name.lower() == TAG_ATTRIBUTES: tag.annotations = self.parse_annotations(tag, tag_annotations) @@ -1193,6 +1229,19 @@ class GtkDocCommentBlockParser(object): warn("annotations not supported for tag '%s:'." % (tag_name, ), position) + + if tag_name.lower() in [TAG_DEPRECATED, TAG_SINCE]: + result = TAG_VALUE_VERSION_RE.match(tag_description) + tag.value = result.group('value') + tag.description = result.group('description') + elif tag_name.lower() == TAG_STABILITY: + result = TAG_VALUE_STABILITY_RE.match(tag_description) + tag.value = result.group('value').capitalize() + tag.description = result.group('description') + elif tag_name.lower() in GI_ANN_TAGS: + tag.value = tag_description + tag.description = '' + comment_block.tags[tag_name.lower()] = tag current_tag = tag continue @@ -1216,11 +1265,7 @@ class GtkDocCommentBlockParser(object): elif in_part == PART_TAGS: self._validate_multiline_annotation_continuation(line, original_line, column_offset, position) - # Append to tag description. - if current_tag.name.lower() in [TAG_RETURNS, TAG_RETURN_VALUE]: - current_tag.description += ' ' + line.strip() - else: - current_tag.value += ' ' + line.strip() + current_tag.description += ' ' + line.strip() continue ######################################################################## diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 6ffec2fb..af9a0a1b 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -595,30 +595,20 @@ class MainTransformer(object): since_tag = block.tags.get(TAG_SINCE) if since_tag is not None: - node.version = since_tag.value + if since_tag.value: + node.version = since_tag.value deprecated_tag = block.tags.get(TAG_DEPRECATED) if deprecated_tag is not None: - value = deprecated_tag.value - if ': ' in value: - delimiter = value.find(': ') - version = value[:delimiter] - desc = value[delimiter + 2:] - else: - desc = value - version = None - node.deprecated = desc - if version is not None: - node.deprecated_version = version + if deprecated_tag.value: + node.deprecated_version = deprecated_tag.value + if deprecated_tag.description: + node.deprecated = deprecated_tag.description stability_tag = block.tags.get(TAG_STABILITY) if stability_tag is not None: - stability = stability_tag.value.capitalize() - if stability in ["Stable", "Unstable", "Private", "Internal"]: - node.stability = stability - else: - message.warn('unknown value "%s" for Stability tag' % ( - stability_tag.value), stability_tag.position) + if stability_tag.value: + node.stability = stability_tag.value annos_tag = block.tags.get(TAG_ATTRIBUTES) if annos_tag is not None: |