Skip to content

Commit 5e29da1

Browse files
Update relevant blocks
1 parent 93dae3a commit 5e29da1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

_tests/test_code_blocks.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,22 @@
3737

3838
REPO_ROOT = Path(__file__).parent.parent
3939

40-
# Blocks that contain any of these patterns are host-Python integration code
41-
# (multilingualprogramming API usage, test harnesses, diagnostic scripts) —
42-
# not standalone multilingual programs intended for execution.
40+
# Blocks whose first line is a host-Python import/shebang — not standalone
41+
# multilingual programs.
4342
HOST_PY_RE = re.compile(
4443
r'^\s*(import\s+[\w.]+|from\s+[\w.]+\s+import\s+|#!/usr/bin/env\s+python\d*(?:\.\d+)*)',
4544
re.MULTILINE,
4645
)
4746

47+
# Orphan API blocks that reference names defined in a prior block in the same
48+
# file (executor, sel, wasm_gen, Lexer, Parser, …). These are documentation
49+
# code fragments, not standalone programs.
50+
PYTHON_API_RE = re.compile(
51+
r'executor\.|BackendSelector\(\)|NumeralConverter\(\)|ProgramExecutor\(\)'
52+
r'|wasm_gen\.|sel\.|Lexer\(language=|Parser\(language='
53+
r'|SemanticAnalyzer\(|ASTPrinter\(\)|\.generate_rust\('
54+
)
55+
4856

4957
# ---------------------------------------------------------------------------
5058
# Block collection
@@ -72,7 +80,7 @@ def _collect_blocks():
7280
code = m.group(2).strip()
7381
if lang in NON_EXECUTABLE or not code:
7482
continue
75-
if HOST_PY_RE.search(code):
83+
if HOST_PY_RE.search(code) or PYTHON_API_RE.search(code):
7684
continue
7785
if 'print(' not in code:
7886
continue

0 commit comments

Comments
 (0)