MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _extract_pascal_regex

Function _extract_pascal_regex

graphify/extract.py:13197–13345  ·  view source on GitHub ↗

Regex fallback for Pascal/Delphi extraction when tree-sitter-pascal is unavailable. Produces the same node/edge schema as the tree-sitter pass.

(path: Path)

Source from the content-addressed store, hash-verified

13195
13196
13197def _extract_pascal_regex(path: Path) -> dict:
13198 """Regex fallback for Pascal/Delphi extraction when tree-sitter-pascal
13199 is unavailable. Produces the same node/edge schema as the tree-sitter pass.
13200 """
13201 try:
13202 raw = path.read_text(encoding="utf-8", errors="replace")
13203 except Exception as exc:
13204 return {"nodes": [], "edges": [], "error": str(exc)}
13205
13206 str_path = str(path)
13207 stem = _file_stem(path)
13208 nodes: list[dict] = []
13209 edges: list[dict] = []
13210 seen_ids: set[str] = set()
13211 seen_call_pairs: set[tuple[str, str]] = set()
13212
13213 def _add_node(nid: str, label: str, line: int) -> None:
13214 if nid not in seen_ids:
13215 seen_ids.add(nid)
13216 nodes.append({
13217 "id": nid,
13218 "label": label,
13219 "file_type": "code",
13220 "source_file": str_path,
13221 "source_location": f"L{line}",
13222 })
13223
13224 def _add_edge(src: str, tgt: str, relation: str, line: int, context: str | None = None) -> None:
13225 edge: dict = {
13226 "source": src,
13227 "target": tgt,
13228 "relation": relation,
13229 "confidence": "EXTRACTED",
13230 "source_file": str_path,
13231 "source_location": f"L{line}",
13232 "weight": 1.0,
13233 }
13234 if context:
13235 edge["context"] = context
13236 edges.append(edge)
13237
13238 def _lineno(text: str, offset: int) -> int:
13239 return text.count("\n", 0, offset) + 1
13240
13241 file_nid = _make_id(str_path)
13242 _add_node(file_nid, path.name, 1)
13243
13244 stripped = _pascal_strip_comments(raw)
13245
13246 # Module header
13247 module_nid = file_nid
13248 mod_m = _PAS_MODULE_RE.search(stripped)
13249 if mod_m:
13250 mod_name = mod_m.group(2)
13251 module_nid = _make_id(stem, mod_name)
13252 _add_node(module_nid, mod_name, _lineno(stripped, mod_m.start()))
13253 _add_edge(file_nid, module_nid, "contains", _lineno(stripped, mod_m.start()))
13254

Callers 1

extract_pascalFunction · 0.85

Calls 14

_file_stemFunction · 0.90
_make_idFunction · 0.90
_pascal_strip_commentsFunction · 0.85
_linenoFunction · 0.85
_pascal_split_sectionsFunction · 0.85
_pascal_split_usesFunction · 0.85
_pascal_resolve_unitFunction · 0.85
_pascal_split_basesFunction · 0.85
_pascal_resolve_classFunction · 0.85
_pascal_find_bodyFunction · 0.85
startMethod · 0.80
_add_nodeFunction · 0.70

Tested by

no test coverage detected