[geany/geany] b5cd53: PHP: fix parsing functions arguments list containing comment or strings

Colomban Wendling git-noreply at xxxxx
Wed Jul 3 17:42:13 UTC 2013


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 15 Apr 2013 17:17:57 UTC
Commit:      b5cd5343fa1b3aaedf60a110ca4c0850a5e68d0e
             https://github.com/geany/geany/commit/b5cd5343fa1b3aaedf60a110ca4c0850a5e68d0e

Log Message:
-----------
PHP: fix parsing functions arguments list containing comment or strings

Instead of hand-parsing the argument list and possibly choking inside
comments, strings, heredoc, etc., use the normal token mechanism and
simply convert the tokens to a string representation as the argument
list.  This technique might perhaps lead to some missing characters in
the argument list representation in the (unlikely) case a token
appearing in the argument list is reported as a generic type for which
it is impossible to know the correct string representation, but this
could always be fixed by adding a specific token type and is anyway
less problematic than maybe breaking further parsing of the document.


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

Modified: tagmanager/ctags/php.c
61 files changed, 51 insertions(+), 10 deletions(-)
===================================================================
@@ -970,28 +970,69 @@ static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
 	{
 		vString *arglist = vStringNew ();
 		int depth = 1;
-		int c;
 
 		vStringPut (arglist, '(');
 		do
 		{
-			c = fileGetc ();
-			if (c != EOF)
+			readToken (token);
+
+			switch (token->type)
 			{
-				vStringPut (arglist, (char) c);
-				if (c == '(')
-					depth++;
-				else if (c == ')')
-					depth--;
+				case TOKEN_OPEN_PAREN:  depth++; break;
+				case TOKEN_CLOSE_PAREN: depth--; break;
+				default: break;
+			}
+			/* display part */
+			switch (token->type)
+			{
+				case TOKEN_AMPERSAND:		vStringPut (arglist, '&');		break;
+				case TOKEN_CLOSE_CURLY:		vStringPut (arglist, '}');		break;
+				case TOKEN_CLOSE_PAREN:		vStringPut (arglist, ')');		break;
+				case TOKEN_CLOSE_SQUARE:	vStringPut (arglist, ']');		break;
+				case TOKEN_COLON:			vStringPut (arglist, ':');		break;
+				case TOKEN_COMMA:			vStringCatS (arglist, ", ");	break;
+				case TOKEN_EQUAL_SIGN:		vStringCatS (arglist, " = ");	break;
+				case TOKEN_OPEN_CURLY:		vStringPut (arglist, '{');		break;
+				case TOKEN_OPEN_PAREN:		vStringPut (arglist, '(');		break;
+				case TOKEN_OPEN_SQUARE:		vStringPut (arglist, '[');		break;
+				case TOKEN_PERIOD:			vStringPut (arglist, '.');		break;
+				case TOKEN_SEMICOLON:		vStringPut (arglist, ';');		break;
+				case TOKEN_STRING:			vStringCatS (arglist, "'...'");	break;
+
+				case TOKEN_IDENTIFIER:
+				case TOKEN_KEYWORD:
+				case TOKEN_VARIABLE:
+				{
+					switch (vStringLast (arglist))
+					{
+						case 0:
+						case ' ':
+						case '{':
+						case '(':
+						case '[':
+						case '.':
+							/* no need for a space between those and the identifier */
+							break;
+
+						default:
+							vStringPut (arglist, ' ');
+							break;
+					}
+					vStringCat (arglist, token->string);
+					break;
+				}
+
+				default: break;
 			}
 		}
-		while (depth > 0 && c != EOF);
+		while (token->type != TOKEN_EOF && depth > 0);
+
 		vStringTerminate (arglist);
 
 		makeFunctionTag (name, arglist, access, impl);
 		vStringDelete (arglist);
 
-		readToken (token); /* normally it's an open brace */
+		readToken (token); /* normally it's an open brace or a semicolon */
 	}
 	if (token->type == TOKEN_OPEN_CURLY)
 		enterScope (token, name->string, K_FUNCTION);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list