I'm using ctags on linux to create tags for source code using vim and the Tlist plug-in. The current ctags function parsing for PHP is woeful so i've downloaded the source for ctags and im going to change the regex that parses the functions.
开发者_Go百科Because i'm dealing with lots of code that has functions declared in many different ways i need a regex to reliably parse the function names properly.
Do you have one you could share that parses a php function name from a line of source code?
This is the current patched and 'improved' one from the ctags source which misses many functions, especially those marked as final
or static
first.
(^[ \t]*)(public[ \t]+|protected[ \t]+|private[ \t]+)?(static[ \t]+)?function[ \t]+&?[ \t]*([" ALPHA "_][" ALNUM "_]*)
Would just adding static and final to the possible list of words to ignore, and making it match more then one of the keywords be close enough?
(^[ \t]*)((public|protected|private|static|final)[ \t]*)*function[ \t]+&?[ \t]*([" ALPHA "_][" ALNUM "_]*)
Would mean it would accept junk like 'public public static final function bogus()', but php's syntax checking will reject it, and therefore shouldn't be a significant issue.
s/^.*\sfunction\s([^\(]*)\(.*$/\1/i
i tested it with some sed
grep -Ri function *| head -10 | sed 's/^.*\sfunction\s\([^\(]*\)(.*$/\1/i'
精彩评论