[geany/geany] 288ada: Python tag parser: fix detection of keywords followed by a tab (\t)

Colomban Wendling git-noreply at geany.org
Thu Dec 6 18:41:14 UTC 2012


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Thu, 06 Dec 2012 18:41:14 UTC
Commit:      288adaffd719a7027a4bb6e9fa28db11f7dbaacd
             https://github.com/geany/geany/commit/288adaffd719a7027a4bb6e9fa28db11f7dbaacd

Log Message:
-----------
Python tag parser: fix detection of keywords followed by a tab (\t)

The Python tag parser used to require a space, and a space only, as the
character following a keyword.  Fix this so it allows any whitespace.


Modified Paths:
--------------
    tagmanager/ctags/python.c

Modified: tagmanager/ctags/python.c
25 files changed, 17 insertions(+), 8 deletions(-)
===================================================================
@@ -631,6 +631,19 @@ static boolean varIsLambda (const char *cp, char **arglist)
 	return is_lambda;
 }
 
+/* checks if @p cp has keyword @p keyword at the start, and fills @p cp_n with
+ * the position of the next non-whitespace after the keyword */
+static boolean matchKeyword (const char *keyword, const char *cp, const char **cp_n)
+{
+	size_t kw_len = strlen (keyword);
+	if (strncmp (cp, keyword, kw_len) == 0 && isspace (cp[kw_len]))
+	{
+		*cp_n = skipSpace (&cp[kw_len + 1]);
+		return TRUE;
+	}
+	return FALSE;
+}
+
 static void findPythonTags (void)
 {
 	vString *const continuation = vStringNew ();
@@ -700,20 +713,17 @@ static void findPythonTags (void)
 		{
 			boolean found = FALSE;
 			boolean is_class = FALSE;
-			if (!strncmp (keyword, "def ", 4))
+			if (matchKeyword ("def", keyword, &cp))
 			{
-				cp = skipSpace (keyword + 3);
 				found = TRUE;
 			}
-			else if (!strncmp (keyword, "class ", 6))
+			else if (matchKeyword ("class", keyword, &cp))
 			{
-				cp = skipSpace (keyword + 5);
 				found = TRUE;
 				is_class = TRUE;
 			}
-			else if (!strncmp (keyword, "cdef ", 5))
+			else if (matchKeyword ("cdef", keyword, &cp))
 		    {
-		        cp = skipSpace(keyword + 4);
 		        candidate = skipTypeDecl (cp, &is_class);
 		        if (candidate)
 		        {
@@ -722,9 +732,8 @@ static void findPythonTags (void)
 		        }
 
 		    }
-    		else if (!strncmp (keyword, "cpdef ", 6))
+    		else if (matchKeyword ("cpdef", keyword, &cp))
 		    {
-		        cp = skipSpace(keyword + 5);
 		        candidate = skipTypeDecl (cp, &is_class);
 		        if (candidate)
 		        {



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).


More information about the Commits mailing list