[geany/geany] af47cc: PHP: report anonymous functions as functions rather than variables
Colomban Wendling
git-noreply at xxxxx
Wed Jul 3 17:41:59 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 16:53:07 UTC
Commit: af47ccf98dbdb9b960cc5c3389423b9d6f9cfbe5
https://github.com/geany/geany/commit/af47ccf98dbdb9b960cc5c3389423b9d6f9cfbe5
Log Message:
-----------
PHP: report anonymous functions as functions rather than variables
Generate a full function tag for anonymous functions:
$anon = function($arg1, $arg2) {
/* ... */
};
Modified Paths:
--------------
tagmanager/ctags/php.c
Modified: tagmanager/ctags/php.c
50 files changed, 37 insertions(+), 13 deletions(-)
===================================================================
@@ -749,24 +749,32 @@ static boolean parseClassOrIface (tokenInfo *const token, const phpKind kind)
}
/* parse a function
+ *
+ * if @name is NULL, parses a normal function
* function myfunc($foo, $bar) {}
- * function &myfunc($foo, $bar) {} */
-static boolean parseFunction (tokenInfo *const token)
+ * function &myfunc($foo, $bar) {}
+ *
+ * if @name is not NULL, parses an anonymous function with name @name
+ * $foo = function($foo, $bar) {} */
+static boolean parseFunction (tokenInfo *const token, const tokenInfo *name)
{
boolean readNext = TRUE;
accessType access = CurrentStatement.access;
implType impl = CurrentStatement.impl;
- tokenInfo *name;
+ tokenInfo *nameFree = NULL;
- readToken (token);
- /* skip a possible leading ampersand (return by reference) */
- if (token->type == TOKEN_AMPERSAND)
+ if (! name)
+ {
readToken (token);
- if (token->type != TOKEN_IDENTIFIER)
- return FALSE;
+ /* skip a possible leading ampersand (return by reference) */
+ if (token->type == TOKEN_AMPERSAND)
+ readToken (token);
+ if (token->type != TOKEN_IDENTIFIER)
+ return FALSE;
- name = newToken ();
- copyToken (name, token, TRUE);
+ name = nameFree = newToken ();
+ copyToken (nameFree, token, TRUE);
+ }
readToken (token);
if (token->type == TOKEN_OPEN_PAREN)
@@ -801,7 +809,8 @@ static boolean parseFunction (tokenInfo *const token)
else
readNext = FALSE;
- deleteToken (name);
+ if (nameFree)
+ deleteToken (nameFree);
return readNext;
}
@@ -884,7 +893,22 @@ static boolean parseVariable (tokenInfo *const token)
copyToken (name, token, TRUE);
readToken (token);
- if (token->type == TOKEN_EQUAL_SIGN || token->type == TOKEN_SEMICOLON)
+ if (token->type == TOKEN_EQUAL_SIGN)
+ {
+ readToken (token);
+ if (token->type == TOKEN_KEYWORD && token->keyword == KEYWORD_function)
+ {
+ if (parseFunction (token, name))
+ readToken (token);
+ readNext = (boolean) (token->type == TOKEN_SEMICOLON);
+ }
+ else
+ {
+ makeSimplePhpTag (name, K_VARIABLE, access);
+ readNext = FALSE;
+ }
+ }
+ else if (token->type == TOKEN_SEMICOLON)
makeSimplePhpTag (name, K_VARIABLE, access);
else
readNext = FALSE;
@@ -926,7 +950,7 @@ static void enterScope (tokenInfo *const parentToken,
{
case KEYWORD_class: readNext = parseClassOrIface (token, K_CLASS); break;
case KEYWORD_interface: readNext = parseClassOrIface (token, K_INTERFACE); break;
- case KEYWORD_function: readNext = parseFunction (token); break;
+ case KEYWORD_function: readNext = parseFunction (token, NULL); break;
case KEYWORD_const: readNext = parseConstant (token); break;
case KEYWORD_define: readNext = parseDefine (token); break;
--------------
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