0

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.

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 "_]*)
3
  • All of your [ \t] should be \s+. public \n function is perfectly valid. Commented Sep 15, 2011 at 21:37
  • It's not mine it's from the source, i'm working to find more robust solution. I'd though i'd ask before writing a monster ;) Commented Sep 15, 2011 at 21:41
  • 1
    why dont you just use Reflection? Commented Sep 15, 2011 at 22:41

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0
s/^.*\sfunction\s([^\(]*)\(.*$/\1/i 

i tested it with some sed

grep -Ri function *| head -10 | sed 's/^.*\sfunction\s\([^\(]*\)(.*$/\1/i'

1 Comment

yeah, just the function name. That's pretty much what i came up with, i think the keywords on the front are just gonna have to be ignored and just check for anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.