[gobject-introspection] annotationparser: Don't eat lines that look like parameters outside param list



commit ff290d2982c6f7a3ee31a8275e9d78bf49ad9dbe
Author: Colin Walters <walters verbum org>
Date:   Sun Aug 14 05:42:53 2011 -0400

    annotationparser: Don't eat lines that look like parameters outside param list
    
    If we're done parsing parameters, previously we would simply eat lines that looked like
        @foo: blah blah
    
    Example is in gtkcssprovider.c.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=656504

 giscanner/annotationparser.py |   14 ++++++++++----
 tests/scanner/regress.c       |   38 ++++++++++++++++++++++++++++++++++++++
 tests/scanner/regress.h       |    1 +
 3 files changed, 49 insertions(+), 4 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 67ba72b..c99cf63 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -509,7 +509,8 @@ class AnnotationParser(object):
             if not line.startswith('*'):
                 lineno += 1
                 continue
-            is_whitespace = self.WHITESPACE_RE.match(line[1:]) is not None
+            nostar_line = line[1:]
+            is_whitespace = self.WHITESPACE_RE.match(nostar_line) is not None
             if parsing_parameters and is_whitespace:
                 # As soon as we find a line that's just whitespace,
                 # we're done parsing the parameters.
@@ -521,12 +522,17 @@ class AnnotationParser(object):
                 lineno += 1
                 continue
 
-            line = line[1:].lstrip()
+            # Explicitly only accept parameters of the form "* @foo" with one space.
+            is_parameter = nostar_line.startswith(' @')
+
+            # Strip the rest of the leading whitespace for the rest of
+            # the code; may not actually be necessary, but still doing
+            # it to avoid regressions.
+            line = nostar_line.lstrip()
 
             # Look for a parameter or return value.  Both of these can
             # have parenthesized options.
             first_colonspace_index = line.find(': ')
-            is_parameter = line.startswith('@')
             is_return_value = self.RETURNS_RE.search(line)
             parse_options = True
             if ((is_parameter or is_return_value)
@@ -594,7 +600,7 @@ class AnnotationParser(object):
                     block.tags[tag_name] = tag
                 else:
                     comment_lines.append(line)
-            elif (not is_parameter):
+            elif not parsing_parameters:
                 comment_lines.append(line)
             lineno += 1
         block.comment = '\n'.join(comment_lines).strip()
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index 938bcf1..276a7d1 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -3210,6 +3210,44 @@ regress_test_multiline_doc_comments (void)
 }
 
 /**
+ * regress_test_nested_parameter:
+ * @a: An integer
+ *
+ * <informaltable>
+ *   <tgroup cols="3">
+ *     <thead>
+ *       <row>
+ *         <entry>Syntax</entry>
+ *         <entry>Explanation</entry>
+ *         <entry>Examples</entry>
+ *       </row>
+ *     </thead>
+ *     <tbody>
+ *       <row>
+ *         <entry>rgb(@r, @g, @b)</entry>
+ *         <entry>An opaque color; @r, @g, @b can be either integers between
+ *                0 and 255 or percentages</entry>
+ *         <entry><literallayout>rgb(128, 10, 54)
+ * rgb(20%, 30%, 0%)</literallayout></entry>
+ *       </row>
+ *       <row>
+ *         <entry>rgba(@r, @g, @b, @a)</entry>
+ *         <entry>A translucent color; @r, @g, @b are as in the previous row,
+ *                @a is a floating point number between 0 and 1</entry>
+ *         <entry><literallayout>rgba(255, 255, 0, 0.5)</literallayout></entry>
+ *       </row>
+ *    </tbody>
+ *  </tgroup>
+ * </informaltable>
+ *
+ * What we're testing here is that the scanner ignores the @a nested inside XML.
+ */
+void
+regress_test_nested_parameter (int a)
+{
+}
+
+/**
  * regress_introspectable_via_alias:
  *
  */
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 4c74e09..25d4358 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -611,6 +611,7 @@ GValue *regress_test_strv_in_gvalue (void);
 GObject * _regress_this_is_a_private_symbol (void);
 
 void regress_test_multiline_doc_comments (void);
+void regress_test_nested_parameter (int a);
 
 /**
  * RegressSkippedStructure: (skip)



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