简体   繁体   English

使用PHP正则表达式从PHP源代码解析函数名称?

[英]Parse function names from PHP source using PHP regex?

I'm using ctags on linux to create tags for source code using vim and the Tlist plug-in. 我在Linux上使用ctags使用vim和Tlist插件为源代码创建标签。 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. 当前针对PHP的ctags函数解析非常糟糕,因此我已经下载了ctags的源代码,而我将更改解析函数的正则表达式。

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? 您是否可以共享一个从一行源代码解析php函数名称的文件?

This is the 这是 current 当前 patched and 'improved' one from the ctags source which misses many functions, especially those marked as final or static first. 从ctags来源修补并“改进”了一项功能,但缺少许多功能,尤其是那些首先标记为finalstatic

(^[ \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? 只是将static和final添加到可能要忽略的单词列表中,并使其匹配得比一个关键字足够接近时才匹配吗?

(^[ \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. 这将意味着它会像“ public public static final function bogus()”那样接受垃圾邮件,但是php的语法检查将拒绝它,因此不应该是一个重大问题。

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

我用一些sed测试了它

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM