Skip to content

det reader: the REPLACE statement is applied (REPLACE ==a== BY ==b==, REPLACE OFF), refused by name where it cannot be (Part of #8412) - #9019

Merged
squid-shepherd[bot] merged 1 commit into
mainfrom
churn/8412-20261122T1053Z
Nov 22, 2026
Merged

squid-shepherd[bot] merged 1 commit into
mainfrom
churn/8412-20261122T1053Z

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #8412. Checklist: done [c:1e95fd31]

What

The line asks whether tab characters and the REPLACE statement (not COPY REPLACING) reach the det path correctly. #8654, #8991, #8999 and #9009 pinned the answer as "refused by name" for REPLACE. This PR replaces the refusal with the real behaviour for the forms it can apply soundly.

  • New det/replace.py, called at the end of source.program_lines (after COPY ... REPLACING, as IBM orders them): REPLACE ==a== BY ==b== [...] rewrites the text that follows (member text included) until the next REPLACE or REPLACE OFF; the statement is removed. Matching is the COPY REPLACING rule (replace_text: whole words, case-insensitive, :TAG: partial words, one left-to-right pass), applied outside literals. Multi-line statements and text after the statement's period are read.
  • Still refused by name, never translated unreplaced: a REPLACE in a COPY member (unchanged), a multi-word pseudo-text operand (its match can span a line break), an empty or non-pseudo-text operand, a missing period, a REPLACE not at the start of its line, a REPLACE still in effect at END PROGRAM. REPLACE FAKEOLD BY FAKENEW. (no pseudo-text) used to pass through silently; it is now refused.
  • Tab-stop expansion is deliberately not added: IBM (the reference) defines no tab handling; expanding to stops of 8 is a GnuCOBOL convention. The standing rule stays: a tab followed only by blanks in columns 1-7 is read (CardDemo CSLKPCDY.cpy, proven), text after a tab there is refused (det reader: a tab in columns 1-7 followed by text inside them is refused by name (Part of #8412) #9009), a tab between tokens is read.

Evidence

  • tests/cobol_mainframe/test_det_tab_replace_8412.py (authored programs, invented names): application, case-insensitivity, whole-word, REPLACE OFF, a second REPLACE superseding the first, multi-line + tail + literal untouched, COPY member text replaced after COPY REPLACING, the five refusals, END PROGRAM, replaced names reaching layout.records. 22 pass with the engine-side file; neighbouring det tests 636 passed.
  • A grep of every .cbl/.cob/.cpy under the mainframe corpora finds 0 REPLACE statements, so no port moves; det_port.py check not run for that reason.
  • Gates: audit_check.py (ruff, mypy, dead-key, doc-refs, ast-accuracy, signal-coverage) OK; pinned ruff 0.17.1 format clean. Not run: pr_gates --ratchets, golden bless (no extraction/detector/language-standards change; det translator source reader only).

Class / Sibling gaps

Class: source-text rewrites and column-layout irregularities reaching the det reader (REPLACE statement, COPY REPLACING, tabs) in the program and in COPY members. Handled: REPLACE in the program, applied (this PR); REPLACE OFF (this PR); REPLACE after COPY REPLACING (this PR); REPLACE in a member, refused by name (#8999); tab in columns 1-7 with text after it, refused (#9009); tab-led blank lines and tabs between tokens, read (#8654, #8991, #9009); COPY REPLACING (#4265).

Sibling gaps (member, status, why not here):

  • Multi-word pseudo-text in REPLACE: refused; needs a token-stream match across line breaks, a different mechanism.
  • REPLACE inside a COPY member and a REPLACE spanning END PROGRAM (batch compile): refused; scope rules need a per-program pass.
  • The engine extractor (extract_boundary) still does not apply REPLACE (names as written, pinned Engine scan side: tabs and the REPLACE statement pinned on authored programs (Part of #8412) #8991): the engine scan, not the det path.
  • COPY REPLACING matches inside string literals (replace_text is not literal-aware); the REPLACE statement here is. Not changed (path shared with the scanner).
  • Tab-stop expansion: not an IBM rule; left as stated.

Lessons for agents

  • det/source.py logical_lines raised on a REPLACE statement for every caller (bll.py, cics.py, dli.py); the new keep_replace flag lets only program_lines keep it for det/replace.py: other readers still refuse.

Co-Authored-By: Claude Sonnet 5.5 [email protected]

🤖 Generated with Claude Code

…F), or refused by name where it cannot be (Part of #8412)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@squid-protocol squid-protocol added the shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md label Nov 22, 2026
@squid-shepherd

Copy link
Copy Markdown
Contributor

No description provided.

@squid-shepherd
squid-shepherd Bot marked this pull request as ready for review November 22, 2026 11:04
@squid-shepherd
squid-shepherd Bot enabled auto-merge (squash) November 22, 2026 11:06
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-shepherd
squid-shepherd Bot merged commit 23b6380 into main Nov 22, 2026
96 checks passed
@squid-shepherd
squid-shepherd Bot deleted the churn/8412-20261122T1053Z branch November 22, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant