Skip to content

prism.py: unqualified '!' inline-comment branch truncates ABAP's real !param syntax, corrupting args counting #1911

Closed

Description

@squid-protocol

Summary

Root cause of the args-counting discrepancy noted as "not yet root-caused" in docs/language_status/abap.md §9. prism.py's _strip_positional_comments() has a "Modern Inline Fortran (!)" comment-stripping branch:

elif "!" in line:
    parts = line.split("!", 1)
    code.append(parts[0])
    lits.append("!" + parts[1])

Unlike the " branch right above it (elif abap_mode and '"' in line:), this one is not gated by abap_mode -- it applies to ABAP unconditionally. ! has no comment meaning in ABAP at all (its only real comment markers are * in column 1 and " inline). But ABAP uses a leading ! to escape formal parameter names in method signatures -- real, extremely common syntax:

CLASS-METHODS pull_by_branch
  IMPORTING
    !iv_url          TYPE string
    !iv_branch_name  TYPE string
  RETURNING
    VALUE(rs_result) TYPE ty_pull_result

Every line like this gets truncated at the !, erasing the parameter name and its TYPE ... clause into the comment stream.

Evidence

zcl_abapgit_git_porcelain.clas.abap: raw file text is 26,121 chars; after prism.py, code_stream is only 23,214 chars -- a ~2,900 char loss that should not happen (shielding is supposed to preserve length/line structure, only blanking content). Direct before/after:

RAW:    '      IMPORTING\n        !iv_url          TYPE string\n        !iv_branch_name  TYPE string\n        !iv_deepen_level TYPE i DEFAULT 1\n      RETURNING\n...'
STRIPPED: '      IMPORTING\n        \n        \n        \n      RETURNING\n...'

Downstream effect on args (IMPORTING|EXPORTING|CHANGING|RETURNING|RECEIVING|EXCEPTIONS regex): with the real parameter names blanked, the pattern's \s+ (which matches across the now-empty lines) reaches the NEXT keyword (RETURNING) and mismatches it as if it were the current keyword's own parameter name -- producing a completely different, larger match set than the real one (31 matches on code_stream vs. 22 on the raw text, zero overlap between the two sets). This is why struct_args disagreed with a raw-regex count in BOTH directions across different files depending on how many !-prefixed parameters and adjacent keywords each file has -- not a simple over/under-count, a structurally corrupted match set.

func_start/class_start were unaffected because their matches come from the IMPLEMENTATION section (METHOD name. / CLASS name IMPLEMENTATION.), which never contains !param syntax -- only the DEFINITION section's method signatures do, which is exactly where args reads from.

Suggested fix

Gate the ! branch the same way the " branch already is: elif not abap_mode and "!" in line: (or equivalent) -- ABAP has no !-based comment convention at all, so this should be a clean full exclusion, not a partial one.

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

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions