[gobject-introspection] [annotationparser] Make it a bit stricter



commit bcf7883320d82ba9078f17e901df771b22b968f9
Author: Johan Dahlin <johan gnome org>
Date:   Thu Sep 23 17:32:58 2010 -0300

    [annotationparser] Make it a bit stricter
    
    Don't parse annotations on lines such as:
    '@param: This is a foo (eg, bar) else: x'
    
    Where there's content between the last ) and the :.

 giscanner/annotationparser.py |   13 ++++++++++++-
 tests/warn/invalid-option.h   |    9 ++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 937b9be..0443553 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -278,8 +278,15 @@ class AnnotationParser(object):
             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)
                 and first_colonspace_index > 0):
+                # Skip lines which has non-whitespace before first (
+                first_paren = line[first_colonspace_index+1:].find('(')
+                if (first_paren != -1 and
+                    line[first_colonspace_index+1:first_paren].strip()):
+                    parse_options = False
+
                 if is_parameter:
                     argname = line[1:first_colonspace_index]
                 else:
@@ -291,7 +298,11 @@ class AnnotationParser(object):
                 if second_colon_index > first_colonspace_index:
                     value_line = \
                       line[first_colonspace_index+2:second_colon_index]
-                    if self.OPTION_RE.search(value_line):
+                    if ')' in value_line:
+                        after_last_paren = value_line[value_line.rfind(')'):]
+                        if not after_last_paren.rstrip().endswith(')'):
+                            parse_options = False
+                    if parse_options and self.OPTION_RE.search(value_line):
                         # The OPTION_RE is a little bit heuristic.  If
                         # we found two colons, we scan inside for something
                         # that looks like (foo).
diff --git a/tests/warn/invalid-option.h b/tests/warn/invalid-option.h
index 22483bb..88cd251 100644
--- a/tests/warn/invalid-option.h
+++ b/tests/warn/invalid-option.h
@@ -1,8 +1,15 @@
 
 /**
  * func:
- * @param: (invalid-annotation-option):
+ * @param: (invalid-annotation-option): sizeof (x) == 1
  */
 void test_func(int param);
 
 // EXPECT:4: Warning: Test: invalid option: invalid-annotation-option
+
+/**
+ * func_weird_gtk_doc:
+ * @param: Foo (e.g. bar) baz:
+ * @param2: This is a (bar):
+ */
+void test_func_weird_gtk_doc(int param, int param2);



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