MCPcopy Create free account
hub / github.com/Snapchat/Valdi / _parse_interfaces

Function _parse_interfaces

tools/api_surface/extract_api.py:27–58  ·  view source on GitHub ↗

Extract interfaces with extends chains and property declarations.

(text: str)

Source from the content-addressed store, hash-verified

25
26
27def _parse_interfaces(text: str) -> dict:
28 """Extract interfaces with extends chains and property declarations."""
29 interfaces = {}
30 pattern = re.compile(
31 r"(?:export\s+)?interface\s+(\w+)"
32 r"(?:\s+extends\s+([\w\s,<>]+?))?"
33 r"\s*\{"
34 )
35 pos = 0
36 while pos < len(text):
37 m = pattern.search(text, pos)
38 if not m:
39 break
40 name = m.group(1)
41 extends_raw = m.group(2) or ""
42 extends = [e.strip() for e in extends_raw.split(",") if e.strip()]
43
44 brace_start = m.end() - 1
45 depth = 1
46 i = brace_start + 1
47 while i < len(text) and depth > 0:
48 if text[i] == "{":
49 depth += 1
50 elif text[i] == "}":
51 depth -= 1
52 i += 1
53 body = text[brace_start + 1 : i - 1]
54
55 properties = _parse_properties(body)
56 interfaces[name] = {"extends": sorted(extends), "properties": properties}
57 pos = i
58 return interfaces
59
60
61def _parse_properties(body: str) -> dict:

Callers 1

extract_apiFunction · 0.85

Calls 4

_parse_propertiesFunction · 0.85
splitMethod · 0.80
endMethod · 0.65
compileMethod · 0.45

Tested by

no test coverage detected