Skip to content

cobol func_start regex's reserved-word shield uses a bare \b, wrongly excluding real paragraphs like DELETE-POLICY-DB2-INFO #1892

Closed

Description

@squid-protocol

Description

Found investigating tri-comparison ledger shape cobol/function/existence/agree[ctags]_vs[gitgalaxy] (verified via tri-comparison-ledger-sweep, Gemini-dispatched read-only investigation, cross-checked directly against source and by running the regex in isolation).

gitgalaxy/standards/language_standards.py's cobol func_start regex bans reserved COBOL verbs/keywords from starting a captured paragraph/section name via a negative lookahead:

r"(?!(?:WORKING-STORAGE|DATA|ENVIRONMENT|IDENTIFICATION|ID|LINKAGE|FILE|DECLARATIVES|"
r"AUTHOR|DATE-WRITTEN|DATE-COMPILED|INSTALLATION|REMARKS|SECURITY|"
r"INPUT-OUTPUT|CONFIGURATION|DISPLAY|CALL|MOVE|COMPUTE|PERFORM|ADD|SUBTRACT|MULTIPLY|"
r"DIVIDE|INITIALIZE|SET|IF|ELSE|GOBACK|EXIT|STOP|EVALUATE|WHEN|READ|WRITE|REWRITE|"
r"DELETE|OPEN|CLOSE|PROGRAM-ID|CLASS-ID|SECTION|DIVISION|END-[A-Za-z0-9_-]+)\b)"

The trailing \b terminating the alternation is a plain word boundary, and - is a non-word character in Python's re, so a boundary exists between any reserved word and a following hyphen. That means a real paragraph name that happens to start with one of these reserved words followed by - (an extremely common COBOL naming convention — verb-prefixed paragraph names) is wrongly excluded, even though it's a completely different, legitimate identifier.

Steps to Reproduce

Verified directly against the compiled regex:

>>> from gitgalaxy.standards.language_standards import LANGUAGE_DEFINITIONS
>>> rx = LANGUAGE_DEFINITIONS["cobol"]["rules"]["func_start"]
>>> rx.search("       DELETE-POLICY-DB2-INFO.")   # real paragraph, cics-genapp/lgdpol01.cbl:139
>>> rx.search("       WRITE-ERROR-MESSAGE.")       # real paragraph, cics-genapp/lgapol01.cbl:137
>>> rx.search("       SET-UP-RECORD.")             # (illustrative)

All three return None — no match — even though the first two are real, called paragraph definitions in the corpus (PERFORM DELETE-POLICY-DB2-INFO / PERFORM WRITE-ERROR-MESSAGE appear earlier in the same files).

A corpus-wide check (grep -rE for a real paragraph definition line starting with any of the banned reserved words followed by -) found ~20 real, affected paragraph names across the language-crucible/data/cobol corpus — this is a systematic recall gap, not a one-off, since verb-prefixed paragraph names (WRITE-*, READ-*, SET-*, DELETE-*, OPEN-*, CLOSE-*, MOVE-*, ADD-*, CALL-*, ...) are a common COBOL naming style.

Suggested fix

Tighten the reserved-word lookahead's trailing boundary so it only excludes the reserved word when it's followed by whitespace/period/newline (a real keyword usage), not when followed by - (part of a longer identifier) — e.g. replace the trailing \b) with something like (?=[ \t\n.])) for that alternation, or require the reserved-word match be followed by [ \t\n] or \. explicitly.

Evidence

Full discrepancy record in docs/self_scan/tri_comparison_ledger.json, shape cobol/function/existence/agree[ctags]_vs[gitgalaxy] (majority-cause is unrelated — see the companion doc note in tests/tools/ctags_reader.py about ctags mistagging COBOL scope terminators like END-IF as paragraphs — this hyphen-boundary bug is the real GitGalaxy-side defect hiding underneath that noisier majority pattern, ~20 of 133 occurrences).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginelegacy-modernizationtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions