From bdb98f0132af9b50e73a920d4856fe1f821fd185 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Tue, 9 Apr 2013 19:41:50 +0200 Subject: [PATCH] PHP: fix parsing of functions returning a reference Fix parsing of functions declarations with a leading ampersand (&), used to make the function return a reference: function &foo($arg1, $arg2) { /* ... */ } --- tagmanager/ctags/php.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tagmanager/ctags/php.c b/tagmanager/ctags/php.c index 267d268b..cd7b7ed4 100644 --- a/tagmanager/ctags/php.c +++ b/tagmanager/ctags/php.c @@ -199,7 +199,8 @@ typedef enum eTokenType { TOKEN_EQUAL_SIGN, TOKEN_OPEN_SQUARE, TOKEN_CLOSE_SQUARE, - TOKEN_VARIABLE + TOKEN_VARIABLE, + TOKEN_AMPERSAND } tokenType; typedef struct { @@ -567,6 +568,7 @@ getNextChar: case '}': token->type = TOKEN_CLOSE_CURLY; break; case '[': token->type = TOKEN_OPEN_SQUARE; break; case ']': token->type = TOKEN_CLOSE_SQUARE; break; + case '&': token->type = TOKEN_AMPERSAND; break; case '=': { @@ -740,6 +742,9 @@ static boolean parseClassOrIface (tokenInfo *const token, phpKind kind) return readNext; } +/* parse a function + * function myfunc($foo, $bar) {} + * function &myfunc($foo, $bar) {} */ static boolean parseFunction (tokenInfo *const token) { boolean readNext = TRUE; @@ -748,6 +753,9 @@ static boolean parseFunction (tokenInfo *const token) tokenInfo *name; readToken (token); + /* skip a possible leading ampersand (return by reference) */ + if (token->type == TOKEN_AMPERSAND) + readToken (token); if (token->type != TOKEN_IDENTIFIER) return FALSE;