From 7ccfdff7c54c3b9e7b5c8ad27233eb60fe247699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Saillant?= Date: Mon, 11 May 2026 22:11:42 +0200 Subject: [PATCH] fix: displace_symbol regex group count The displace_at callback referenced m.group(4) but the regex defines only 3 capture groups (prefix, x, tail). IndexError killed scale-up runs (--max-projects 30 hit this on a leaf schematic that did have a matchable (symbol (at x y a)) block). Fix: collapse y + angle into the 3rd group, format as f\"{pre}{x + 500}{tail}\". Adjusted regex closing paren so the tail group includes the closing ). Scale-up validated: 28 triplets across 60 intact projects: permissive: 19 (truncate_tail x14 + drop_global_label x5) copyleft: 9 (truncate_tail x8 + drop_global_label x1) --- datasets/builders/build_kicad_d2_combined.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datasets/builders/build_kicad_d2_combined.py b/datasets/builders/build_kicad_d2_combined.py index c7d5fdb..f2528e7 100644 --- a/datasets/builders/build_kicad_d2_combined.py +++ b/datasets/builders/build_kicad_d2_combined.py @@ -348,14 +348,14 @@ def inject_noise(sch_text: str, pcb_text: str | None, elif noise_op == "displace_symbol": # Find first symbol with (at x y angle) and increment x by 500mil + # Regex has 3 groups: prefix, x, tail (y + angle + closing paren) def displace_at(m): pre = m.group(1) x = int(m.group(2)) - y = m.group(3) - angle = m.group(4) - return f"{pre}(at {x + 500} {y} {angle})" + tail = m.group(3) # contains " y angle" + return f"{pre}{x + 500}{tail}" bad_sch = re.sub( - r'(\(symbol[^)]*?\(at\s+)(-?\d+)(\s+-?\d+\s+[\d.]+)\)', + r'(\(symbol[^)]*?\(at\s+)(-?\d+)(\s+-?\d+\s+[\d.]+\))', displace_at, bad_sch, count=1 )