SF.net SVN: geany: [2669] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Jun 9 17:12:19 UTC 2008


Revision: 2669
          http://geany.svn.sourceforge.net/geany/?rev=2669&view=rev
Author:   ntrel
Date:     2008-06-09 10:12:19 -0700 (Mon, 09 Jun 2008)

Log Message:
-----------
Refactor using findVariable().

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tagmanager/python.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-06-09 15:03:53 UTC (rev 2668)
+++ trunk/ChangeLog	2008-06-09 17:12:19 UTC (rev 2669)
@@ -2,6 +2,8 @@
 
  * tagmanager/python.c:
    Fix variable names sometimes having leading junk characters.
+ * tagmanager/python.c:
+   Refactor using findVariable().
 
 
 2008-06-07  Frank Lanitz  <frank(at)frank(dot)uvena(dot)de>

Modified: trunk/tagmanager/python.c
===================================================================
--- trunk/tagmanager/python.c	2008-06-09 15:03:53 UTC (rev 2668)
+++ trunk/tagmanager/python.c	2008-06-09 17:12:19 UTC (rev 2669)
@@ -434,6 +434,47 @@
 	}
 }
 
+static const char *findVariable(const char *line)
+{
+	/* Parse global and class variable names (C.x) from assignment statements.
+	 * Object attributes (obj.x) are ignored.
+	 * Assignment to a tuple 'x, y = 2, 3' not supported.
+	 * TODO: ignore duplicate tags from reassignment statements. */
+	const char *cp, *sp, *eq, *start;
+
+	cp = strstr(line, "=");
+	if (! cp)
+		return NULL;
+	eq = cp + 1;
+	while (*eq)
+	{
+		if (*eq == '=')
+			return NULL;	/* ignore '==' operator and 'x=5,y=6)' function lines */
+		if (*eq == '(')
+			break;	/* allow 'x = func(b=2,y=2,' lines */
+		eq++;
+	}
+	if (*eq == '=')
+		return NULL;	/* can this happen? */
+
+	/* go backwards to the start of the line, checking we have valid chars */
+	start = cp - 1;
+	while (start >= line && isspace ((int) *start))
+		--start;
+	while (start >= line && isIdentifierCharacter ((int) *start))
+		--start;
+	if (!isIdentifierFirstCharacter(*(start + 1)))
+		return NULL;
+	sp = start;
+	while (sp >= line && isspace ((int) *sp))
+		--sp;
+	if ((sp + 1) != line)	/* the line isn't a simple variable assignment */
+		return NULL;
+	/* the line is valid, parse the variable name */
+	++start;
+	return start;
+}
+
 static void findPythonTags (void)
 {
 	vString *const continuation = vStringNew ();
@@ -450,7 +491,7 @@
 	{
 		const char *cp = line;
 		char *longstring;
-		const char *keyword;
+		const char *keyword, *variable;
 		int indent;
 
 		cp = skipSpace (cp);
@@ -536,41 +577,12 @@
 			}
 		}
 		/* Find global and class variables */
-		if ((cp = strstr(line, "=")))
+		variable = findVariable(line);
+		if (variable)
 		{
-			/* Parse global and class variable names (C.x) from assignment statements.
-			 * Object attributes (obj.x) are ignored.
-			 * Assignment to a tuple 'x, y = 2, 3' not supported.
-			 * TODO: ignore duplicate tags from reassignment statements. */
-			const char *sp, *eq, *start;
+			const char *start = variable;
 			boolean parent_is_class;
 
-			eq = cp + 1;
-			while (*eq)
-			{
-				if (*eq == '=')
-					goto skipvar;	/* ignore '==' operator and 'x=5,y=6)' function lines */
-				if (*eq == '(')
-					break;	/* allow 'x = func(b=2,y=2,' lines */
-				eq++;
-			}
-			if (*eq == '=')
-				continue;
-			/* go backwards to the start of the line, checking we have valid chars */
-			start = cp - 1;
-			while (start >= line && isspace ((int) *start))
-				--start;
-			while (start >= line && isIdentifierCharacter ((int) *start))
-				--start;
-			if (!isIdentifierFirstCharacter(*(start + 1)))
-				goto skipvar;
-			sp = start;
-			while (sp >= line && isspace ((int) *sp))
-				--sp;
-			if ((sp + 1) != line)	/* the line isn't a simple variable assignment */
-				goto skipvar;
-			/* the line is valid, parse the variable name */
-			++start;
 			vStringClear (name);
 			while (isIdentifierCharacter ((int) *start))
 			{
@@ -587,8 +599,6 @@
 			makeVariableTag (name, parent);
 
 			vStringClear (name);
-			skipvar:
-			; /* dummy */
 		}
 	}
 	/* Clean up all memory we allocated. */


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list