Skip to content

Shared COBOL preprocessor in gitgalaxy/core: one layout/continuation/COPY/REPLACING/conditional expander with a line map, used by both the scanner and the COBOL→Java translator #5648

Closed

Description

@squid-protocol

Why

The scanner and the COBOL→Java translator each turn COBOL files into "the program the compiler sees", separately. The fact cross-check gate (#4273, fact-crosscheck.yml) catches them disagreeing, but not sharing a blind spot: on 2026-10-19 both missed COPY "ws-state.cpy". (scanner #5618 / PR #5626, translator #5645), so they agreed and the gate stayed green. BMS already follows the shared pattern (the translator imports core.bms_screen_fields / core.bms_symbolic), as do core.cobol_source_format, core.source_text.read_source and core.compiler_options. Do the same for the rest of the text-level front end.

What the preprocessor does (one module in gitgalaxy/core, no tree-sitter, zero-dependency)

Input: a COBOL source file + copy libraries. Output: the expanded program text plus a line map (every expanded line → original file and line).

  1. Layout: fixed format (sequence area 1-6, indicator 7: * / comment, D debug, - continuation; text past 72) and free format (*>), >>SOURCE FORMAT switching. Reuse core/cobol_source_format.py.
  2. Continuations: join continued literals and words (- in column 7).
  3. COPY: find COPY name [OF|IN lib] in every spelling (unquoted, quoted, quoted with extension "x.cpy"), resolve the member (core/copy_libraries.py, the engine already owns resolution since det translator: take COPY resolution from the engine (ownership per #4273), replacing the first-hit directory search #4468), insert it, recursively, with cycle detection.
  4. Substitution: COPY … REPLACING (==pseudo-text==, partial words, :TAG: templates), the REPLACE statement, conditional compilation (>>IF/>>ELSE/>>END-IF, >>DEFINE) per the compiler options already parsed by core.compiler_options.
  5. Line map, so findings and generated Java point at CUSTREC.cpy:12, not a line of the expanded text.
    Out of scope: EXEC SQL/CICS/DLI blocks pass through untouched; statement parsing and record layouts stay where they are (the translator's tree-sitter grammar is byte-proven against GnuCOBOL, Translator front-end bake-off: which COBOL parser should the det translator use? #4378).

Where it replaces duplicate code

  • Translator: gitgalaxy/tools/cobol_to_java/det/source.py expand() (:728), _replacing/_replace (:809/:820), copy_names/_copy_match/_COPY (:652-:665), comment/free-format helpers (:288, :574, :581), as_fixed/as_fixed_rows (:1001).
  • Scanner: gitgalaxy/core/mainframe_boundary.py _copy_replacing (:641), _continued_literal (:552); the REPLACING application in gitgalaxy/tools/cobol_to_cobol/galaxy_ir.py (COBOL engine: a section-level COPY ... REPLACING is not applied to the copied 01 records (misnamed or missing) #4457); any COPY regex in standards/language_standards/languages/cobol.py.

Acceptance

Part of the CICS→Java path (Training Montage). Follow-up: #5649 (translator consumes engine layouts).

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    core-engine
    priority: high
    scope:core
    lane:nyx
    on Oct 19, 2026
  2. 19 remaining items

  3. squid-protocol commented on Oct 22, 2026

    @squid-protocol
    OwnerAuthor

    Churn run 5648-20261022T1542Z (host nyx) ended without a PR. No change: translator det/source.py already on shared preprocessor. #5648 left open: scanner side (mainframe_boundary, galaxy_ir) and line-map consumption not verified.

  4. squid-protocol commented on Oct 23, 2026

    @squid-protocol
    OwnerAuthor

    Claimed by promoter-bot host nyx, lease renewed 2026-10-23T07:29Z. It lapses after 6 h without a renewal. To take it back, assign someone or remove the claim:nyx label.

  5. squid-protocol commented on Oct 23, 2026

    @squid-protocol
    OwnerAuthor

    Closing: audit on origin/main shows every acceptance item met (shared core preprocessor used by det/source.py and mainframe_boundary.py, #5645 fixed, fact_ownership.md note, fixed+free-format tests). Caveat for the doc's 'Not yet shared' section: the scanner does not yet call expand() or consume the line map (needs a golden bless, no consumer yet); file separately if wanted.

  6. squid-protocol commented on Oct 23, 2026

    @squid-protocol
    OwnerAuthor

    Churn run 5648-20261023T0744Z (host nyx) ended without a PR. audit: all acceptance met, issue closed; no PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claim:nyxcore-engineenhancementlane:nyxpriority: highscope:core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions