MCPcopy Create free account
hub / github.com/ElementsProject/elements / parse_function_calls

Function parse_function_calls

test/lint/lint-format-strings.py:28–47  ·  view source on GitHub ↗

Return an array with all calls to function function_name in string source_code. Preprocessor directives and C++ style comments ("//") in source_code are removed. >>> len(parse_function_calls("foo", "foo();bar();foo();bar();")) 2 >>> parse_function_calls("foo", "foo(1);bar(1);foo(2);

(function_name, source_code)

Source from the content-addressed store, hash-verified

26
27
28def parse_function_calls(function_name, source_code):
29 """Return an array with all calls to function function_name in string source_code.
30 Preprocessor directives and C++ style comments ("//") in source_code are removed.
31
32 >>> len(parse_function_calls("foo", "foo();bar();foo();bar();"))
33 2
34 >>> parse_function_calls("foo", "foo(1);bar(1);foo(2);bar(2);")[0].startswith("foo(1);")
35 True
36 >>> parse_function_calls("foo", "foo(1);bar(1);foo(2);bar(2);")[1].startswith("foo(2);")
37 True
38 >>> len(parse_function_calls("foo", "foo();bar();// foo();bar();"))
39 1
40 >>> len(parse_function_calls("foo", "#define FOO foo();"))
41 0
42 """
43 assert type(function_name) is str and type(source_code) is str and function_name
44 lines = [re.sub("// .*", " ", line).strip()
45 for line in source_code.split("\n")
46 if not line.strip().startswith("#")]
47 return re.findall(r"[^a-zA-Z_](?=({}\(.*).*)".format(function_name), " " + " ".join(lines))
48
49
50def normalize(s):

Callers 1

mainFunction · 0.85

Calls 3

formatMethod · 0.80
typeClass · 0.50
joinMethod · 0.45

Tested by

no test coverage detected