Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(health): register Pascal in complexity, duplication, and dataflow dialects (#1629)

Laentir Valetove8ea33abc501
diff --git a/docs/layers/LANGUAGE_SUPPORT.md b/docs/layers/LANGUAGE_SUPPORT.md
index 15f214d52..149b815f5 100644
--- a/docs/layers/LANGUAGE_SUPPORT.md
+++ b/docs/layers/LANGUAGE_SUPPORT.md
@@ -26,7 +26,7 @@ produce meaningful output.
| Tier | Languages | What works |
|------|-----------|------------|
| [**Full**](#full-tier) | Python · TypeScript · JavaScript · Svelte · Vue · Java · Kotlin · Go · Rust · C++ · C# · Scala · Ruby | AST parsing, import resolution, named bindings, call resolution, heritage, docstrings, framework-aware edges, dynamic-hint extractors, and **code-health markers** |
-| [**Good**](#good-tier) | C · Swift · PHP · Dart · Object Pascal | Everything above except code-health markers (C, Swift, PHP, Object Pascal; Dart *does* get health markers). Dedicated workspace resolvers and framework edges per language, except Object Pascal, which resolves imports via the generic stem-map fallback (see [Known gaps](#object-pascal-known-gaps)) |
+| [**Good**](#good-tier) | C · Swift · PHP · Dart · Object Pascal | Everything above except code-health markers (C, Swift, PHP; Dart and Object Pascal *do* get health markers). Dedicated workspace resolvers and framework edges per language, except Object Pascal, which resolves imports via the generic stem-map fallback (see [Known gaps](#object-pascal-known-gaps)) |
| [**SQL / dbt**](#sql--dbt) | `.sql` via sqlglot | Tables / views / functions / procedures as symbols with wiki pages; dbt projects get real `ref()` / `source()` lineage |
| **Shell** | `.sh` `.bash` `.zsh` | Function definitions as symbols, `source` / `.` import edges (incl. `$SCRIPT_DIR` / `dirname` / `$BATS_ROOT` idioms), and function-level code-health complexity (CCN, nesting, cognitive). No class metrics, heritage, bindings, or dead-code flagging |
| **Config / data** | OpenAPI · Protobuf · GraphQL · Dockerfile · Makefile · YAML · JSON · TOML · Terraform · Markdown | In the file tree and wiki; special handlers extract endpoints / targets where applicable |
@@ -44,7 +44,7 @@ produce meaningful output.
| Call graph edges | ✅ | ✅ | - | - | - |
| Heritage (extends/implements) | ✅ | ✅ | - | - | - |
| Named bindings | ✅ | ✅ | - | - | - |
-| Code-health markers | ✅² | Dart only | - | - | - |
+| Code-health markers | ✅² | Dart, Object Pascal | - | - | - |
| Dead code detection | ✅ | ✅ | ✅ | ✅ | - |
| Semantic search & wiki pages | ✅ | ✅ | ✅ | ✅ | ✅ |
@@ -170,7 +170,7 @@ mixins). Dedicated workspace resolvers per language.
| **Swift** | `.swift` | `import` with SPM `Package.swift` target → directory mapping; intra-module type references; `@main` entry points |
| **PHP** | `.php` | `use Foo\Bar\Baz` with composer.json PSR-4 longest-prefix resolution; Laravel, TYPO3 edges |
| **Dart** | `.dart` | `import` / `export` / `part` URIs; `package:` via every `pubspec.yaml`; Flutter route tables and `runApp()` edges; **code-health markers** |
-| **Object Pascal** | `.pas` `.pp` `.dpr` `.dpk` `.lpr` `.inc` | `uses UnitA, UnitB;` resolved via the generic unit-name → file-stem fallback (no dedicated resolver); `.dpr`/`.dpk`/`.lpr` project files as entry points |
+| **Object Pascal** | `.pas` `.pp` `.dpr` `.dpk` `.lpr` `.inc` | `uses UnitA, UnitB;` resolved via the generic unit-name → file-stem fallback (no dedicated resolver); `.dpr`/`.dpk`/`.lpr` project files as entry points; **code-health markers** |
### Object Pascal known gaps
@@ -191,8 +191,20 @@ are less battle-tested than C/Swift/PHP/Dart's:
Lightweight tier, rather than a project-file-aware resolver — accurate for
the near-universal "unit name equals file stem" convention, wrong when it
doesn't hold.
-- **No code-health markers yet** (complexity, duplication, dataflow dialects
- aren't registered for Pascal).
+- **No class-level metrics (LCOM4 / god-class).** Pascal splits a class into
+ an interface-only declaration (method signatures, no bodies) and a fully
+ separate implementation section where each qualified method (`TFoo.Bar`) is
+ its own top-level node — there is no single AST node that groups a type's
+ method *bodies* the way class-level analysis expects. Same posture as Go
+ (external-receiver methods): left unmapped rather than emitting classes
+ with `method_count == 0`. Function-level complexity/nesting and duplication
+ are unaffected — see [code-health coverage](#code-health-coverage).
+- **No assertion-smell or performance-risk markers yet** (no assert-call or
+ call-node kinds registered).
+- **No Extract Method (dataflow) support yet** — the CFG builder has real
+ branch/loop/try node kinds, but no `DefUseDialect` is registered, so
+ def/use and reaching-definitions stay silent (the same "later" state as
+ C# / Kotlin / Scala / Ruby).
- **One known grammar gap left unhandled deliberately:** an anonymous
`array[...] of record ... end` element type has no tree-sitter-pascal rule
and degrades to a wrong `parent_name` for whatever the same class declares
@@ -314,6 +326,7 @@ is "Full" vs "Good".
| Scala | ✅ | ✅ | ✅⁴ | later | ✅⁵ |
| Ruby | ✅ | ✅⁶ | ✅⁷ | later | ✅⁸ |
| Shell | ✅⁹ | n/a | n/a | n/a | n/a |
+| Object Pascal | ✅ | n/a¹⁴ | later | later | n/a |
¹ Go methods attach to a type via an external receiver rather than nesting in a
class body, so class-level metrics aren't computable; Go gets the function- and
@@ -414,6 +427,18 @@ body/else resolution in the CFG core.
honest: shell branching is chained command lists. There are no classes,
assertions, dataflow, or perf dialect for shell.
+¹⁴ **Pascal has no single node grouping a type's method bodies.** A class
+declaration (`declType` → `declClass`) holds only method *signatures*
+(`declProc`, no body); the implementation of each qualified method
+(`TFoo.Bar`) is a separate top-level node keyed by name, not nested inside
+the class. Class-level analysis expects methods physically nested in the
+class node, so mapping it here would silently emit a `ClassComplexity` with
+`method_count == 0` for every class — same posture as Go's external-receiver
+methods (footnote 1): left unmapped rather than emit a misleading zero.
+Function-level complexity/nesting/cognitive and the CFG (branch/loop/try/with,
+raise) are unaffected; no `DefUseDialect` is registered yet, so Extract Method
+stays at "no signal" like C# / Kotlin / Scala / Ruby.
+
The **performance** signal (`io_in_loop`, `string_concat_in_loop`,
`resource_construction_in_loop`, language-specific markers like Go
`defer_in_loop` and C# sync-over-async) and the **dataflow** layer (powering
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
index d28cb3075..0d28fc864 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/ast_utils.py
@@ -27,6 +27,25 @@ _DECLARATOR_NAME_KINDS = frozenset(
)
+def _pascal_unwrap_name(name: Node) -> Node:
+ """Pascal: unwrap ``genericDot`` (``TFoo.Bar``) / ``genericTpl`` (``Bar<T>``)
+ name wrappers down to the leaf identifier.
+
+ ``declProc``/``declType``'s ``name`` field is one of four shapes (bare
+ identifier, generic, qualified, qualified+generic — see queries.scm's
+ node-shape reference); only the leaf identifier is the human-readable
+ name, so both wrapper kinds are peeled before falling back to the node
+ itself (never ``None``, so a caller can always read ``.text``).
+ """
+ if name.type == "genericDot":
+ rhs = name.child_by_field_name("rhs")
+ return _pascal_unwrap_name(rhs) if rhs is not None else name
+ if name.type == "genericTpl":
+ entity = name.child_by_field_name("entity")
+ return entity if entity is not None else name
+ return name
+
+
def _find_name(node: Node) -> str:
"""Best-effort: return the text of the first identifier child."""
# Search a couple of common field names first.
@@ -34,6 +53,16 @@ def _find_name(node: Node) -> str:
child = node.child_by_field_name(field_name)
if child is not None and child.text is not None:
return child.text.decode("utf-8", errors="replace")
+ # Pascal: a ``defProc``'s name lives two hops down, on its ``header``
+ # field's own ``name`` field (``defProc`` itself carries no ``name``) —
+ # unwrap any qualified/generic wrapper before reading the text.
+ if node.type == "defProc":
+ header = node.child_by_field_name("header")
+ name = header.child_by_field_name("name") if header is not None else None
+ if name is not None and name.text is not None:
+ leaf = _pascal_unwrap_name(name)
+ if leaf.text is not None:
+ return leaf.text.decode("utf-8", errors="replace")
# C / C++: the function name is not a direct child but nested inside a
# ``declarator`` chain (``function_definition → function_declarator →
# field_identifier``). Languages with a ``name`` field never reach here.
@@ -76,6 +105,12 @@ def _find_assigned_lambda_name(node: Node) -> str | None:
left = next((child for child in parent.children if child is not node), None)
if left is not None and left.text is not None:
return _node_text(left)
+ if parent.type == "assignment":
+ # Pascal ``Proc := procedure ... end`` — the field is ``lhs``,
+ # not ``left``.
+ lhs = parent.child_by_field_name("lhs")
+ if lhs is not None and lhs.text is not None:
+ return _node_text(lhs)
if parent.type not in {"parenthesized_expression", "as_expression", "satisfies_expression"}:
return None
parent = parent.parent
@@ -188,6 +223,16 @@ def _count_parameters(fn_node: Node) -> int:
sig = _dart_signature_sibling(fn_node)
if sig is not None:
params = next((c for c in sig.children if c.type == "formal_parameter_list"), None)
+ if params is None and fn_node.type == "lambda":
+ # Pascal anonymous procedure/function: the arg list is its own
+ # ``args`` field directly (parameterless procedures omit it).
+ params = fn_node.child_by_field_name("args")
+ if params is None and fn_node.type == "defProc":
+ # Pascal named procedure/function: the arg list lives on the
+ # ``header`` field's own ``args`` field, not on ``defProc`` itself.
+ header = fn_node.child_by_field_name("header")
+ if header is not None:
+ params = header.child_by_field_name("args")
if params is None:
return 0
count = 0
@@ -209,6 +254,14 @@ def _count_parameters(fn_node: Node) -> int:
"positional_separator",
):
continue
+ if child.type == "declArg":
+ # Pascal groups same-typed parameters under one ``declArg``
+ # (``A, B, C: Boolean``) -- one node, three names -- so counting
+ # the node itself would undercount; count its direct
+ # ``identifier`` children instead (the trailing ``type`` child
+ # is a different node type and never matches).
+ count += sum(1 for gc in child.children if gc.type == "identifier")
+ continue
if child.is_named:
count += 1
return count
diff --git a/packages/core/src/repowise/core/analysis/health/complexity/languages.py b/packages/core/src/repowise/core/analysis/health/complexity/languages.py
index deefc1c0c..cb55f33b2 100644
--- a/packages/core/src/repowise/core/analysis/health/complexity/languages.py
+++ b/packages/core/src/repowise/core/analysis/health/complexity/languages.py
@@ -719,6 +719,67 @@ _SHELL = LanguageNodeMap(
)
+_PASCAL = LanguageNodeMap(
+ # ``defProc`` pairs a signature (``header: declProc``) with a ``body``
+ # block field -- the interface-only ``declProc`` forward/interface
+ # declaration carries no body and is deliberately NOT a function kind
+ # (nothing to walk; the implementation-section ``defProc`` is the one
+ # physical node with a measurable body). Anonymous procedure/function
+ # literals (``Proc := procedure begin ... end``) are a distinct
+ # ``lambda`` node type that also carries its own ``body`` field.
+ function_kinds=frozenset({"defProc"}),
+ lambda_kinds=frozenset({"lambda"}),
+ # ``if`` / ``ifElse`` are two distinct node types for bare-then vs.
+ # then/else. An ``else if`` chain nests a fresh ``if``/``ifElse`` one
+ # level inside the ``else`` field rather than a flat elif-clause, so the
+ # recursive walker already counts one branch per level without special
+ # casing.
+ branch_kinds=frozenset({"if", "ifElse"}),
+ loop_kinds=frozenset({"for", "while", "repeat"}),
+ try_kinds=frozenset({"try"}),
+ # A bound handler (``on E: Exception do``) is an ``exceptionHandler``
+ # node; a bare ``except ... end`` with no ``on`` clauses has no such
+ # node at all (the statements sit directly under ``except``), so a
+ # parameterless catch-all is undercounted -- the safe direction, same
+ # posture Dart takes for its bare ``on FormatException {}``.
+ catch_kinds=frozenset({"exceptionHandler"}),
+ switch_kinds=frozenset({"case"}),
+ # The ``else`` branch of a ``case`` has no dedicated node (its
+ # statements sit directly under ``case``, same shape as the bare
+ # ``except``), so it doesn't add a caseCase count -- undercounted, safe.
+ case_kinds=frozenset({"caseCase"}),
+ # ``and`` / ``or`` are named keyword-TOKEN node types in this grammar
+ # (``kAnd`` / ``kOr``, siblings of the operands inside ``exprBinary``),
+ # not generic operator text inside a binary node, so no text-sniffing
+ # set is needed here (unlike the C-family languages above).
+ boolean_operator_kinds=frozenset({"kAnd", "kOr"}),
+ # No class-level metrics: Pascal splits a class into an interface-only
+ # ``declClass`` (method SIGNATURES only, via ``declProc`` -- no bodies)
+ # and a fully separate implementation section where each qualified
+ # method (``TFoo.Bar``) is its own top-level ``defProc``. There is no
+ # single node that groups a type's method BODIES the way
+ # ``_collect_class_methods`` expects (``declClass``'s children are
+ # forward declarations only), so mapping ``class_kinds`` here would
+ # silently emit a ``ClassComplexity`` with ``method_count == 0`` for
+ # every class. Same posture as Go (external-receiver methods): left
+ # unmapped rather than emitting a misleading zero-method class.
+ if_kinds=frozenset({"if", "ifElse"}),
+ block_kinds=frozenset({"block"}),
+ # No dedicated ``return`` node -- ``Result := ...`` is an ordinary
+ # assignment and a bare ``Exit`` / ``Exit(...)`` is an ordinary
+ # identifier/call statement, so neither edges to the CFG exit specially
+ # (safe under-signal, not a crash).
+ return_kinds=frozenset(),
+ raise_kinds=frozenset({"raise"}),
+ # ``Break`` / ``Continue`` are ordinary identifiers (a bare
+ # ``statement`` wrapping an ``identifier``), not dedicated node types --
+ # same under-signal posture as ``return_kinds``.
+ break_kinds=frozenset(),
+ continue_kinds=frozenset(),
+ with_kinds=frozenset({"with"}),
+)
+
+
LANGUAGE_MAPS: dict[str, LanguageNodeMap] = {
"python": _PY,
"typescript": _TS,
@@ -739,6 +800,7 @@ LANGUAGE_MAPS: dict[str, LanguageNodeMap] = {
"scala": _SCALA,
"ruby": _RUBY,
"shell": _SHELL,
+ "pascal": _PASCAL,
}
diff --git a/packages/core/src/repowise/core/analysis/health/duplication/tokenizer.py b/packages/core/src/repowise/core/analysis/health/duplication/tokenizer.py
index ac00903ea..7473ae5d4 100644
--- a/packages/core/src/repowise/core/analysis/health/duplication/tokenizer.py
+++ b/packages/core/src/repowise/core/analysis/health/duplication/tokenizer.py
@@ -71,6 +71,13 @@ _LITERAL_KINDS = frozenset(
"nil",
"None",
"boolean",
+ # Pascal (tree-sitter-pascal): numbers and strings are ``literalNumber``
+ # / ``literalString``; ``True`` / ``False`` / ``Nil`` are named keyword
+ # tokens (``kTrue`` / ``kFalse`` / ``kNil``), which fall through to the
+ # raw-text branch below like any other keyword -- fine, since their
+ # text is already the shortest possible normalized form.
+ "literalNumber",
+ "literalString",
}
)
diff --git a/packages/core/src/repowise/core/ingestion/extractors/heritage/pascal.py b/packages/core/src/repowise/core/ingestion/extractors/heritage/pascal.py
index df1489056..6a9ce57bc 100644
--- a/packages/core/src/repowise/core/ingestion/extractors/heritage/pascal.py
+++ b/packages/core/src/repowise/core/ingestion/extractors/heritage/pascal.py
@@ -11,6 +11,42 @@ from ..helpers import node_text
_CLASS_LIKE_KINDS = {"declClass", "declIntf", "declHelper"}
+def _extract_parents(type_node: Node, name: str, src: str) -> list[str]:
+ """The comma-separated ``parent`` list -- `class(TBase, IFoo, IBar)` --
+ minus blanks and self-references.
+
+ Pascal's grammar puts the base class and every implemented interface in
+ the *same* list, with no syntax distinguishing "the one base class"
+ from "the interfaces". By (near-universal) convention the first entry
+ is the base class and the rest are interfaces; nothing in the grammar
+ enforces that ordering, so the caller's "first = extends, rest =
+ implements" split is a best-effort heuristic, not a guarantee.
+ """
+ parent_nodes = type_node.children_by_field_name("parent")
+ parents = [bare_type_name(node_text(p, src)) for p in parent_nodes if p.type == "typeref"]
+ return [p for p in parents if p and p != name]
+
+
+def _extract_helper_extended_types(type_node: Node, name: str, src: str) -> list[str]:
+ """The type(s) a `class helper` extends -- `class helper(...) for TFoo`.
+
+ This is a distinct relationship from the helper's own ancestor helper
+ (the `parent` list, handled by ``_extract_parents``). It carries no
+ field name in the grammar (`$.kFor, $.typeref` with no `field()`
+ wrapper), so it's located positionally: every named `typeref` child not
+ already consumed as a `parent`.
+ """
+ parent_ids = {p.id for p in type_node.children_by_field_name("parent")}
+ extended: list[str] = []
+ for child in type_node.named_children:
+ if child.type != "typeref" or child.id in parent_ids:
+ continue
+ text = bare_type_name(node_text(child, src))
+ if text and text != name:
+ extended.append(text)
+ return extended
+
+
def _extract_pascal_heritage(
def_node: Node, name: str, line: int, src: str, out: list[HeritageRelation]
) -> None:
@@ -22,13 +58,6 @@ def _extract_pascal_heritage(
in ``languages/specs/pascal.py`` on why ``heritage_node_types`` points
at ``declType``. Drill into declType's `type` field first to reach the
actual class/interface/helper body.
-
- Pascal's grammar puts the base class and every implemented interface in
- the *same* comma-separated `parent` list -- `class(TBase, IFoo, IBar)`
- -- with no syntax distinguishing "the one base class" from "the
- interfaces". By (near-universal) convention the first entry is the base
- class and the rest are interfaces; nothing in the grammar enforces that
- ordering, so this is a best-effort heuristic, not a guarantee.
"""
type_children = def_node.children_by_field_name("type")
if not type_children:
@@ -37,11 +66,7 @@ def _extract_pascal_heritage(
if type_node.type not in _CLASS_LIKE_KINDS:
return
- parent_nodes = type_node.children_by_field_name("parent")
- parents = [bare_type_name(node_text(p, src)) for p in parent_nodes if p.type == "typeref"]
- parents = [p for p in parents if p and p != name]
-
- for i, parent in enumerate(parents):
+ for i, parent in enumerate(_extract_parents(type_node, name, src)):
out.append(
HeritageRelation(
child_name=name,
@@ -52,21 +77,7 @@ def _extract_pascal_heritage(
)
if type_node.type == "declHelper":
- # The type being extended (`for TFoo`) is a distinct relationship
- # from the helper's own ancestor helper (`parent`, handled above).
- # It carries no field name in the grammar (`$.kFor, $.typeref` with
- # no `field()` wrapper), so it's located positionally: the last
- # named `typeref` child not already consumed as `parent`.
- parent_typeref_ids = {p.id for p in parent_nodes}
- for child in type_node.named_children:
- if child.type == "typeref" and child.id not in parent_typeref_ids:
- extended = bare_type_name(node_text(child, src))
- if extended and extended != name:
- out.append(
- HeritageRelation(
- child_name=name,
- parent_name=extended,
- kind="extends",
- line=line,
- )
- )
+ for extended in _extract_helper_extended_types(type_node, name, src):
+ out.append(
+ HeritageRelation(child_name=name, parent_name=extended, kind="extends", line=line)
+ )
diff --git a/tests/fixtures/lang_samples/pascal/complex.pas b/tests/fixtures/lang_samples/pascal/complex.pas
new file mode 100644
index 000000000..d9180d6e7
--- /dev/null
+++ b/tests/fixtures/lang_samples/pascal/complex.pas
@@ -0,0 +1,48 @@
+unit Complex;
+
+interface
+
+implementation
+
+function ManyBranches(A, B, C, D, E: Boolean): Integer;
+begin
+ if A then
+ begin
+ Result := 1;
+ end
+ else if B then
+ begin
+ Result := 2;
+ end
+ else if C then
+ begin
+ Result := 3;
+ end
+ else if D then
+ begin
+ Result := 4;
+ end
+ else if E then
+ begin
+ Result := 5;
+ end;
+
+ if A and B then
+ begin
+ Result := 6;
+ end;
+
+ if C or D then
+ begin
+ Result := 7;
+ end;
+
+ if A and C and E then
+ begin
+ Result := 8;
+ end;
+
+ Result := 0;
+end;
+
+end.
diff --git a/tests/fixtures/lang_samples/pascal/nested.pas b/tests/fixtures/lang_samples/pascal/nested.pas
new file mode 100644
index 000000000..8ae6c5926
--- /dev/null
+++ b/tests/fixtures/lang_samples/pascal/nested.pas
@@ -0,0 +1,37 @@
+unit Nested;
+
+interface
+
+implementation
+
+function DeeplyNested(X: Integer): Integer;
+var
+ I: Integer;
+begin
+ if X > 0 then
+ begin
+ for I := 0 to X do
+ begin
+ if I mod 2 = 0 then
+ begin
+ while I > 0 do
+ begin
+ if I = 5 then
+ begin
+ Result := I;
+ Exit;
+ end;
+ Dec(I);
+ end;
+ end;
+ end;
+ end;
+ Result := 0;
+end;
+
+function Shallow(X: Integer): Integer;
+begin
+ Result := X + 1;
+end;
+
+end.
diff --git a/tests/unit/health/test_complexity_walker.py b/tests/unit/health/test_complexity_walker.py
index 7c02ec54c..66250b07f 100644
--- a/tests/unit/health/test_complexity_walker.py
+++ b/tests/unit/health/test_complexity_walker.py
@@ -111,6 +111,46 @@ def test_go_nested_depth():
assert deep.max_nesting >= 4
+def test_pascal_nested_depth():
+ results = _walk("pascal/nested.pas", "pascal")
+ deep = _find(results, "DeeplyNested")
+ shallow = _find(results, "Shallow")
+ assert deep is not None
+ assert shallow is not None
+ assert deep.max_nesting >= 4, f"expected ≥4 nesting, got {deep.max_nesting}"
+ assert shallow.max_nesting == 0
+ assert deep.ccn > shallow.ccn
+ assert shallow.param_count == 1
+
+
+def test_pascal_complex_method_ccn():
+ results = _walk("pascal/complex.pas", "pascal")
+ many = _find(results, "ManyBranches")
+ assert many is not None
+ assert many.ccn >= 9, f"expected CCN ≥ 9, got {many.ccn}"
+ assert many.param_count == 5
+
+
+def test_pascal_no_class_metrics():
+ # Pascal method bodies live in a top-level ``defProc`` outside the
+ # ``declClass`` node (see languages.py's ``_PASCAL`` comment) -- class
+ # metrics are deliberately unmapped rather than emitting a misleading
+ # zero-method class, same posture as Go.
+ fcx = walk_file(
+ "unsupported.pas",
+ "pascal",
+ (
+ b"unit U;\n interface\n type\n TFoo = class\n"
+ b" public\n procedure Bar;\n end;\n"
+ b" implementation\n"
+ b" procedure TFoo.Bar;\n begin\n end;\n"
+ b" end.\n"
+ ),
+ )
+ assert fcx.classes == []
+ assert _find(fcx.functions, "Bar") is not None
+
+
def test_javascript_nested_depth():
results = _walk("javascript/nested.js", "javascript")
deep = _find(results, "deeplyNested")
diff --git a/tests/unit/health/test_duplication.py b/tests/unit/health/test_duplication.py
index 2dd22bbf6..df77f0a66 100644
--- a/tests/unit/health/test_duplication.py
+++ b/tests/unit/health/test_duplication.py
@@ -70,6 +70,18 @@ def test_tokenize_file_drops_comments_and_normalizes_identifiers():
assert not any("comment" in k for k in kinds)
+def test_tokenize_file_pascal_normalizes_identifiers_and_literals():
+ source = (
+ b"unit U;\n interface\n implementation\n"
+ b" procedure Foo;\n begin\n WriteLn('hello', 42);\n end;\n end.\n"
+ )
+ toks = tokenize_file("pascal", source)
+ kinds = [t.kind for t in toks]
+ assert "ID" in kinds # WriteLn / Foo collapsed
+ assert "LIT" in kinds # 'hello' / 42 collapsed
+ assert not any("literalString" in k or "literalNumber" in k for k in kinds)
+
+
def _write(tmp_path: Path, name: str, src: str) -> Path:
p = tmp_path / name
p.write_text(src)
diff --git a/tests/unit/ingestion/parser/test_pascal.py b/tests/unit/ingestion/parser/test_pascal.py
index bfc89393e..aeeb82ae5 100644
--- a/tests/unit/ingestion/parser/test_pascal.py
+++ b/tests/unit/ingestion/parser/test_pascal.py
@@ -393,6 +393,39 @@ class TestPascalHeritage:
# IInterface is also a builtin_parent for Pascal.
assert not any(child == "ICalcTarget" for child, _kind, _parent in rels)
+ def test_class_helper_extends_both_ancestor_and_extended_type(
+ self, parser: ASTParser
+ ) -> None:
+ # `class helper(TBaseHelper) for TFoo` carries two distinct
+ # relationships: the helper's own ancestor helper (`parent`, same
+ # list as a plain class) and the type it extends (`for TFoo`,
+ # positional -- no field name in the grammar). Both must surface.
+ src = b"""\
+unit HelperUnit;
+
+interface
+
+type
+ TBaseHelper = class helper for TObject
+ end;
+
+ TFooHelper = class helper(TBaseHelper) for TFoo
+ procedure Bar;
+ end;
+
+implementation
+
+procedure TFooHelper.Bar;
+begin
+end;
+
+end.
+"""
+ result = parser.parse_file(_pas("HelperUnit.pas"), src)
+ rels = {(r.child_name, r.kind, r.parent_name) for r in result.heritage}
+ assert ("TFooHelper", "extends", "TBaseHelper") in rels
+ assert ("TFooHelper", "extends", "TFoo") in rels
+
class TestPascalEncoding:
"""Non-ASCII (Cyrillic) content -- see PR #1353 review follow-up on