Skip to content

Commit

Permalink
PHP: Fix parsing of anonymous functions returning a reference
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Aug 8, 2013
1 parent 9fbe2bc commit fb7bd34
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tagmanager/ctags/php.c
Expand Up @@ -1084,28 +1084,30 @@ static boolean parseTrait (tokenInfo *const token)
* function &myfunc($foo, $bar) {}
*
* if @name is not NULL, parses an anonymous function with name @name
* $foo = function($foo, $bar) {} */
* $foo = function($foo, $bar) {}
* $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 *nameFree = NULL;

readToken (token);
/* skip a possible leading ampersand (return by reference) */
if (token->type == TOKEN_AMPERSAND)
readToken (token);

if (! 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;

name = nameFree = newToken ();
copyToken (nameFree, token, TRUE);
readToken (token);
}

readToken (token);
if (token->type == TOKEN_OPEN_PAREN)
{
vString *arglist = vStringNew ();
Expand Down
1 change: 1 addition & 0 deletions tests/ctags/Makefile.am
Expand Up @@ -13,6 +13,7 @@ test_sources = \
3526726.tex \
68hc11.asm \
angle_bracket.cpp \
anonymous_functions.php \
array_ref_and_out.cs \
array_spec.f90 \
array-spec.f90 \
Expand Down
24 changes: 24 additions & 0 deletions tests/ctags/anonymous_functions.php
@@ -0,0 +1,24 @@
<?php

$a = function() {};

$b = function($x, $y) {};

/* return a value */
$c = function() {
return 42;
};

/* return a function */
$d = function() {
return function() {
return "hello";
};
};

/* return by reference */
$_g = 42;
$e = function&() {
global $_g;
return $_g;
};
7 changes: 7 additions & 0 deletions tests/ctags/anonymous_functions.php.tags
@@ -0,0 +1,7 @@
# format=tagmanager
_g�16384�0
a�16�()�0
b�16�($x, $y)�0
c�16�()�0
d�16�()�0
e�16�()�0

0 comments on commit fb7bd34

Please sign in to comment.