我如何在VIM中生成PHP源文件中包含特定字符串的函数名称列表?
答案 0 :(得分:1)
你应该看看ctags。为源文件(或整个项目)创建标记文件,并使用例如:ts /hello
来查找名称中包含hello
的所有函数(或类)。
答案 1 :(得分:0)
python程序怎么样?请注意,您应该使用PLY ....
替换其中一些内容#!/usr/bin/env python
'''
Project: Python parser to search php functions for regex
Author: Spencer Rathbun
Date: 1/17/2012
Summary: Search glob files (assumed to be php source) for input regex, and list function and line numbers where found.
'''
import re, argparse
from glob import glob
def main(regex, infiles):
theRegex = re.compile(regex)
currFunction = ''
for globFile in infiles:
for f in glob(globFile):
with open(f,'rb') as currFile:
for lineNum, line in enumerate(currFile.readlines()):
if line.split(' ')[0] == 'function':
currFunction = line.split(' ')[1].split('(')[0]
if theRegex.search(line) != None:
print("In function {0}\n\tLine {1}: {2}".format(currFunction, lineNum+1, line))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Search php source code for regex', version='%(prog)s 1.0')
parser.add_argument('regex', type=str, default='', help='Regular expression')
parser.add_argument('infiles', nargs='+', type=str, help='list of input files')
args = parser.parse_args()
main(args.regex, args.infiles)
将其添加到~/bin
并使其可执行。然后在vim中,您可以使用:!phpSearch.py yourRegex yourGlobPat
调用它。