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

Function _parse_enums

tools/api_surface/extract_api.py:178–203  ·  view source on GitHub ↗

Extract const enum definitions with their members.

(text: str)

Source from the content-addressed store, hash-verified

176
177
178def _parse_enums(text: str) -> dict:
179 """Extract const enum definitions with their members."""
180 enums = {}
181 pattern = re.compile(r"(?:export\s+)?(?:const\s+)?enum\s+(\w+)\s*\{")
182 pos = 0
183 while pos < len(text):
184 m = pattern.search(text, pos)
185 if not m:
186 break
187 name = m.group(1)
188 brace_start = m.end() - 1
189 depth = 1
190 i = brace_start + 1
191 while i < len(text) and depth > 0:
192 if text[i] == "{":
193 depth += 1
194 elif text[i] == "}":
195 depth -= 1
196 i += 1
197 body = text[brace_start + 1 : i - 1]
198 members = {}
199 for mm in re.finditer(r"(\w+)\s*=\s*([^,}]+)", body):
200 members[mm.group(1)] = mm.group(2).strip()
201 enums[name] = dict(sorted(members.items()))
202 pos = i
203 return dict(sorted(enums.items()))
204
205
206def _parse_class_methods(text: str) -> dict:

Callers 1

extract_apiFunction · 0.85

Calls 2

endMethod · 0.65
compileMethod · 0.45

Tested by

no test coverage detected