我想要一个正则表达式,其中我将与Python re模块一起使用,它将在Python文件中查找Python函数调用,但是在我要查找的函数调用周围会有一些警告。
下面是我要在文件中查找的函数的示例用法:
# Simple function call.
f("_key")
# The chained function call, in the simplest format (no args).
f("_key").g()
# The chained function call with simple arguments.
f("_key").g("hello", 1337)
# The chained function call with possible, more complex arguments
f("_key").g(obj.blah(), {"dog":"cat"})
# And then the possibility for long function calls to extend over one line
f("_key").g(
"dogs",
"cats",
{"living":"together"})
还有一个常见的免责声明:我做了一个搜索,问题和我很接近,但我想知道我的需求是否受到足够的限制,可以绕过“常规与非常规”的语言问题。这是因为我不是计算机科学专业的学生,害怕正则表达式。
FWIW,这是Grammar/Grammar的摘录:
这些情况需要由正则表达式处理,以捕获所有函数调用而不出现任何误报。
与其使用regex,不如使用Python标准库附带的工具集之一:
compile()后跟dis.dis()来定位函数调用
ast.Call识别函数调用
这应该符合您的要求:
相关问题 更多 >
编程相关推荐