[gobject-introspection] annotationparser: indent _parse_comment_block gtkdoc code



commit f41525d54f53edd9b0d665397f7c6c755ee3616b
Author: Alban Browaeys <prahal yahoo com>
Date:   Tue Apr 10 01:06:45 2012 +0200

    annotationparser: indent _parse_comment_block gtkdoc code
    
    The current logic in _parse_comment_block of the annotationparser
    check the identifier and use variables that only makes sense if a
    result was returned (column_offset, original_line). This patch
    indent the logic so it is only triggered if a result is found.
    Otherwise it returns None as expected by call chain
    "parse >  parse_comment_block > _parse_comment_block":
    ie in "parse":
       comment_block = self.parse_comment_block(comment)
       if comment_block is not None:
    
    This still raises a lot of warnings but does not abort while generating
    gir for libgnomekbd, mutter or telepathy-glib (those thus have to be
    tweaked not to call g-ir-scanner with --warn-error at least until the
    parser mask those false positives or the doc from those projects is
    fixed to comply with the behaviour expected by giscanner).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=673806

 giscanner/annotationparser.py |  179 +++++++++++++++++++++--------------------
 tests/scanner/regress.h       |    8 ++
 2 files changed, 98 insertions(+), 89 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index a1df7d5..97f2566 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -620,85 +620,85 @@ class AnnotationParser(object):
                 # Get rid of ' * ' at start of the line.
                 line = line[result.end(0):]
 
-            ####################################################################
-            # Check for GTK-Doc comment block identifier.
-            ####################################################################
-            if not comment_block:
-                # The correct identifier name would have the colon at the end
-                # but maintransformer.py does not expect us to do that. So
-                # make sure to compute an identifier_name without the colon and
-                # a real_identifier_name with the colon.
-
-                if not identifier:
-                    result = SECTION_RE.search(line)
-                    if result:
-                        identifier = IDENTIFIER_SECTION
-                        real_identifier_name = 'SECTION:%s' % (result.group('section_name'))
-                        identifier_name = real_identifier_name
-                        column = result.start('section_name') + column_offset
-
-                if not identifier:
-                    result = SYMBOL_RE.search(line)
-                    if result:
-                        identifier = IDENTIFIER_SYMBOL
-                        real_identifier_name = '%s:' % (result.group('symbol_name'))
-                        identifier_name = '%s' % (result.group('symbol_name'))
-                        column = result.start('symbol_name') + column_offset
-
-                if not identifier:
-                    result = PROPERTY_RE.search(line)
-                    if result:
-                        identifier = IDENTIFIER_PROPERTY
-                        real_identifier_name = '%s:%s:' % (result.group('class_name'),
-                                                           result.group('property_name'))
-                        identifier_name = '%s:%s' % (result.group('class_name'),
-                                                     result.group('property_name'))
-                        column = result.start('property_name') + column_offset
-
-                if not identifier:
-                    result = SIGNAL_RE.search(line)
-                    if result:
-                        identifier = IDENTIFIER_SIGNAL
-                        real_identifier_name = '%s::%s:' % (result.group('class_name'),
-                                                            result.group('signal_name'))
-                        identifier_name = '%s::%s' % (result.group('class_name'),
-                                                      result.group('signal_name'))
-                        column = result.start('signal_name') + column_offset
-
-                if identifier:
-                    in_part = PART_IDENTIFIER
-
-                    comment_block = DocBlock(identifier_name)
-                    comment_block.set_position(position)
-
-                    if 'annotations' in result.groupdict():
-                        comment_block.options = self.parse_options(comment_block,
-                                                                   result.group('annotations'))
-
-                    if 'colon' in result.groupdict() and result.group('colon') != ':':
-                        colon_start = result.start('colon')
-                        colon_column = column_offset + colon_start
-                        marker = ' '*colon_column + '^'
-                        message.warn("missing ':' at column %s:\n%s\n%s" %
-                                     (colon_start, original_line, marker),
-                                     position)
-                    continue
-                else:
-                    # If we get here, the identifier was not recognized, so
-                    # ignore the rest of the block just like the old annotation
-                    # parser did. Doing this is a bit more strict than
-                    # gtkdoc-mkdb (which continues to search for the identifier
-                    # until either it is found or the end of the block is
-                    # reached). In practice, however, ignoring the block is the
-                    # right thing to do because sooner or later some long
-                    # descriptions will contain something matching an identifier
-                    # pattern by accident.
-                    marker = ' '*column_offset + '^'
-                    message.warn('ignoring unrecognized GTK-Doc comment block, identifier not '
-                                 'found:\n%s\n%s' % (original_line, marker),
-                                 position)
-
-                    return None
+		####################################################################
+		# Check for GTK-Doc comment block identifier.
+		####################################################################
+		if not comment_block:
+		    # The correct identifier name would have the colon at the end
+		    # but maintransformer.py does not expect us to do that. So
+		    # make sure to compute an identifier_name without the colon and
+		    # a real_identifier_name with the colon.
+
+		    if not identifier:
+			result = SECTION_RE.search(line)
+			if result:
+			    identifier = IDENTIFIER_SECTION
+			    real_identifier_name = 'SECTION:%s' % (result.group('section_name'))
+			    identifier_name = real_identifier_name
+			    column = result.start('section_name') + column_offset
+
+		    if not identifier:
+			result = SYMBOL_RE.search(line)
+			if result:
+			    identifier = IDENTIFIER_SYMBOL
+			    real_identifier_name = '%s:' % (result.group('symbol_name'))
+			    identifier_name = '%s' % (result.group('symbol_name'))
+			    column = result.start('symbol_name') + column_offset
+
+		    if not identifier:
+			result = PROPERTY_RE.search(line)
+			if result:
+			    identifier = IDENTIFIER_PROPERTY
+			    real_identifier_name = '%s:%s:' % (result.group('class_name'),
+							       result.group('property_name'))
+			    identifier_name = '%s:%s' % (result.group('class_name'),
+							 result.group('property_name'))
+			    column = result.start('property_name') + column_offset
+
+		    if not identifier:
+			result = SIGNAL_RE.search(line)
+			if result:
+			    identifier = IDENTIFIER_SIGNAL
+			    real_identifier_name = '%s::%s:' % (result.group('class_name'),
+								result.group('signal_name'))
+			    identifier_name = '%s::%s' % (result.group('class_name'),
+							  result.group('signal_name'))
+			    column = result.start('signal_name') + column_offset
+
+		    if identifier:
+			in_part = PART_IDENTIFIER
+
+			comment_block = DocBlock(identifier_name)
+			comment_block.set_position(position)
+
+			if 'annotations' in result.groupdict():
+			    comment_block.options = self.parse_options(comment_block,
+								       result.group('annotations'))
+
+			if 'colon' in result.groupdict() and result.group('colon') != ':':
+			    colon_start = result.start('colon')
+			    colon_column = column_offset + colon_start
+			    marker = ' '*colon_column + '^'
+			    message.warn("missing ':' at column %s:\n%s\n%s" %
+					 (colon_start, original_line, marker),
+					 position)
+			continue
+		    else:
+			# If we get here, the identifier was not recognized, so
+			# ignore the rest of the block just like the old annotation
+			# parser did. Doing this is a bit more strict than
+			# gtkdoc-mkdb (which continues to search for the identifier
+			# until either it is found or the end of the block is
+			# reached). In practice, however, ignoring the block is the
+			# right thing to do because sooner or later some long
+			# descriptions will contain something matching an identifier
+			# pattern by accident.
+			marker = ' '*column_offset + '^'
+			message.warn('ignoring unrecognized GTK-Doc comment block, identifier not '
+				     'found:\n%s\n%s' % (original_line, marker),
+				     position)
+
+			return None
 
             ####################################################################
             # Check for comment block parameters.
@@ -863,19 +863,20 @@ class AnnotationParser(object):
         ########################################################################
         # We have picked up a couple of \n characters that where not
         # intended. Strip those.
-        if comment_block.comment:
-            comment_block.comment = comment_block.comment.strip()
-        else:
-            comment_block.comment = ''
+        if comment_block is not None:
+	    if comment_block.comment:
+		comment_block.comment = comment_block.comment.strip()
+	    else:
+		comment_block.comment = ''
 
-        for tag in comment_block.tags.itervalues():
-            self._clean_comment_block_part(tag)
+	    for tag in comment_block.tags.itervalues():
+		self._clean_comment_block_part(tag)
 
-        for param in comment_block.params.itervalues():
-            self._clean_comment_block_part(param)
+	    for param in comment_block.params.itervalues():
+		self._clean_comment_block_part(param)
 
-        # Validate and store block.
-        comment_block.validate()
+	    # Validate and store block.
+	    comment_block.validate()
         return comment_block
 
     def _clean_comment_block_part(self, part):
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 1740145..43d9bd3 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -786,4 +786,12 @@ void regress_test_struct_fixed_array_frob (RegressTestStructFixedArray *str);
 void regress_has_parameter_named_attrs (int        foo,
                                         gpointer   attributes);
 
+/**
+
+ * regress_test_invalid_comment:
+ * @foo: a param
+ *
+ * invalid comment with a line without
+ * https://bugzilla.gnome.org/show_bug.cgi?id=673806
+ */
 #endif /* __GITESTTYPES_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]