[geany/geany] cc9e56: PHP: Fix parsing of anonymous functions using the "use" keyword

Colomban Wendling git-noreply at xxxxx
Thu Aug 8 15:27:25 UTC 2013


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Thu, 08 Aug 2013 15:27:25 UTC
Commit:      cc9e56e9bc1624dcebd4c2cae9010edd9acb1936
             https://github.com/geany/geany/commit/cc9e56e9bc1624dcebd4c2cae9010edd9acb1936

Log Message:
-----------
PHP: Fix parsing of anonymous functions using the "use" keyword

http://www.php.net/manual/en/language.namespaces.php#104136


Modified Paths:
--------------
    tagmanager/ctags/php.c
    tests/ctags/anonymous_functions.php
    tests/ctags/anonymous_functions.php.tags

Modified: tagmanager/ctags/php.c
30 files changed, 28 insertions(+), 2 deletions(-)
===================================================================
@@ -1085,7 +1085,8 @@ static boolean parseTrait (tokenInfo *const token)
  *
  * if @name is not NULL, parses an anonymous function with name @name
  * 	$foo = function($foo, $bar) {}
- * 	$foo = function&($foo, $bar) {} */
+ * 	$foo = function&($foo, $bar) {}
+ * 	$foo = function($foo, $bar) use ($x, &$y) {} */
 static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
 {
 	boolean readNext = TRUE;
@@ -1176,8 +1177,33 @@ static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
 		makeFunctionTag (name, arglist, access, impl);
 		vStringDelete (arglist);
 
-		readToken (token); /* normally it's an open brace or a semicolon */
+		readToken (token); /* normally it's an open brace or "use" keyword */
 	}
+
+	/* skip use(...) */
+	if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_use)
+	{
+		readToken (token);
+		if (token->type == TOKEN_OPEN_PAREN)
+		{
+			int depth = 1;
+
+			do
+			{
+				readToken (token);
+				switch (token->type)
+				{
+					case TOKEN_OPEN_PAREN:  depth++; break;
+					case TOKEN_CLOSE_PAREN: depth--; break;
+					default: break;
+				}
+			}
+			while (token->type != TOKEN_EOF && depth > 0);
+
+			readToken (token);
+		}
+	}
+
 	if (token->type == TOKEN_OPEN_CURLY)
 		enterScope (token, name->string, K_FUNCTION);
 	else


Modified: tests/ctags/anonymous_functions.php
7 files changed, 7 insertions(+), 0 deletions(-)
===================================================================
@@ -22,3 +22,10 @@
   global $_g;
   return $_g;
 };
+
+$f = function&() use (&$_g) {
+  
+  function f_sub() {}
+  
+  return $_g;
+};


Modified: tests/ctags/anonymous_functions.php.tags
2 files changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -5,3 +5,5 @@ b
 c�16�()�0
 d�16�()�0
 e�16�()�0
+f�16�()�0
+f_sub�16�()�f�0



--------------
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