core: shield string literals in positional comment stripper (#259) - #2506
Merged
Merged
Conversation
`Prism._strip_positional_comments` (the `positional_anchored` / `positional_abap` families -- cobol, fortran, abap) split each line directly on `*>` / `!` / `"` with no string-literal shielding, unlike every other stripping path in prism.py (`_strip_single_line_comments`, `_strip_segment_comments`, `_strip_nested_comments` all mask via `LITERAL_MASK_PATTERN` first). A delimiter-shaped character inside a literal -- `DISPLAY "Rate *> 5%"`, `PRINT *, "Warning!"`, ABAP `x = 'he said "hi"'` -- was misread as a real inline-comment marker: the tail of the literal plus the rest of the statement moved to the comment stream and `code_stream` was left with a dangling unterminated quote, deflating `coding_loc` and dropping real structural signals. Fix: mask literals per line (the same bounded discipline `_strip_single_line_comments` adopted for #1184) before the inline `*>` / `"` / `!` search, restoring them into both halves after the split. The column-1 / column-7 anchor check stays on the raw line so column positions are exact. ABAP masks single-quote / backtick only -- its `"` is the comment delimiter, not a string quote (new `ABAP_LITERAL_MASK_PATTERN`). `_mask_line_literals` gains an optional `pattern` override. Column-7 `-` continued literals remain out of scope (masking is deliberately line-bounded). Golden masters re-blessed (both modes): 5 diffs, all on `cobol/che-che4z_lsp_project_fixtures/special_schema.cbl`, whose DATA VALUE clauses hold XML-ish string literals containing `!` (`'<itemName>Not here!</itemName>'`). With the literal no longer truncated at the `!`, one previously-hidden `safety_bypasses` signal is now correctly retained (0 -> 1) and its downstream risk-exposure percentages shift. No line-shift noise anywhere else across the ~80-repo corpus. Closes #259 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ni57RP5ATiqfN3XzJvRDPY
Contributor
Owner
Author
|
The failing Tracked separately in #2507 (also covers the All other checks green: crucible-audit both modes, full-suite-matrix ×40, tri-comparison, ruff/mypy/dead-key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Prism._strip_positional_comments(thepositional_anchored/positional_abapfamilies — cobol, fortran, abap) split each line directly on*>/!/"with no string-literal shielding, unlike every other stripping path inprism.py(_strip_single_line_comments,_strip_segment_comments,_strip_nested_commentsall mask viaLITERAL_MASK_PATTERNfirst).A delimiter-shaped character inside a string literal was misread as a real inline-comment marker:
Same failure for the
!branch (DISPLAY "Warning!") and the ABAP"branch (x = 'he said "hi"'). The tail of the literal + rest of the statement moved to the comment stream, deflatingcoding_locand silently dropping real structural signals.The prior closure ("resolved by #273") referenced the wrong PR — #273 only touched
network_risk_sensor.py. #1745 fixed a different bug in the same function (line-count geometry). No regression test guarded this.Fix
_strip_single_line_commentsadopted for Contiguous 'dead zones' of real functions silently lost from extraction on production files, independent of mid-file language drift #1184) before the inline*>/"/!search, restoring them into both the code and comment halves after the split."is the comment delimiter, not a string quote (newABAP_LITERAL_MASK_PATTERN)._mask_line_literalsgains an optionalpatternoverride (backward compatible).-indicator — masking is deliberately line-bounded (Contiguous 'dead zones' of real functions silently lost from extraction on production files, independent of mid-file language drift #1184). Noted in the code comment.Golden masters (re-blessed, both modes)
python tests/tools/update_golden_master.pyrun once per mode. 5 diffs, all on one file:cobol/che-che4z_lsp_project_fixtures/special_schema.cbl, whoseDATA ... VALUEclauses hold XML-ish string literals containing!(' <itemName>Not here!</itemName>'). With the literal no longer truncated at the!:Type/Safety Bypasses: 0 → 1 (a real signal previously hidden in the mis-stripped comment portion)Error & Exception Exposure: 62.98% → 65.52% on that file, + 3 aggregate rollupsNo line-shift noise anywhere else across the corpus.
Verification
tests/core_engine/(572 passed) + newtest_prism.pycases (delimiter-inside-literal for cobol*>/!, fortran!, abap", plus real-inline-comment control cases)_strictsiblings (412 passed)tests/tools/crucible_check.py— both modes PASS after re-blesstri_comparison_chart.py --all --ci,tree_sitter_accuracy_audit.py --all --ci(pre-existing unrelatedcsscorpus-drift failure reproduces on cleanmainwith these changes stashed — not introduced here)ruff_audit.py --ci,mypy_audit.py --ci,dead_key_audit.py --ci,ruff format --checkonprism.pyCloses #259
🤖 Generated with Claude Code