Repository navigation
fix(perl): teach prism.py's comment stripper about quote-like operators - #1690
Merged
Merged
Conversation
perl's '#'-to-end-of-line comment stripper (prism.py's
_strip_single_line_comments) had no awareness of perl's quote-like
operators (qq{...}, q{...}, etc.) OR of /regex/ literals (bare or
keyword-prefixed: m/.../, s/.../.../, etc.) -- any '#' character
appearing as literal CONTENT inside either of those, on the same line,
was misread as a real comment start, stripping everything from that '#'
to end-of-line before detector.py ever saw it. Confirmed on 3 real corpus
functions (language-crucible/data/perl):
- mojo/Template.pm::_line: `return qq{#line @{[shift]} "$name"};` -- the
`#line` right after `qq{` is real quote-op content (a perl #line
directive template), wrongly read as a comment, desyncing everything
downstream through end of file.
- exiftool/exiftool::FilterArgfileLine: `if ($arg =~ /^#/) { # comment...`
-- the bare `/^#/` regex literal's own '#' misread as a comment start
with no keyword prefix at all, swallowing 1048 lines instead of ~23 and
hiding the real definition of ReadStayOpen entirely.
- spamassassin/Makefile.PL::MY::dist: `next if $line =~ /^\s*#/;` -- same
mechanism, same bare-regex-with-embedded-'#' shape.
Added a perl-gated masking pass in _strip_single_line_comments that runs
before the '#'-delimiter search: brace-delimited quote-ops (qq{}/q{}/etc,
balanced-brace scan with backslash-escape handling) and both keyword-
prefixed (m/, s/, tr/, y/) and bare /regex/ literals (a preceding-token
heuristic disambiguates regex-open from division: `=~`/`!~`/`(`/`,`/`;`/
`{`/`&&`/`||` or a keyword like if/unless/while/split/grep/map/return
immediately before a bare '/' means regex-open; an identifier/number/')'/
']' means division).
Two additional real bugs found and fixed during verification, beyond the
original diagnosis:
- prism.py's _restore_masked_literals used a single-pass re.sub, which
didn't fully unmask nested literal structures (e.g. a quote inside
s{...}{...}) -- now loops until no __MASK_N__ tokens remain.
- detector.py's _build_brace_safe_stream ran its generic quote-shielding
pass BEFORE perl's own quote-op/regex shielding, so a quote inside a
regex body could still mispair with an unrelated quote downstream,
corrupting brace-depth counting -- this was the actual reason
exiftool::FilterArgfileLine was still swallowing 1000+ lines even after
the prism.py fix alone. Reordered: perl skips the early generic pass and
re-runs it after perl-specific shielding instead.
Before -> after (full pipeline, not isolated unit calls):
- mojo/Template.pm::_line: hundreds of lines swallowed -> 5 LOC (236-240)
- exiftool::FilterArgfileLine: 1200+ LOC -> 23 LOC (4893-4915)
- exiftool::ReadStayOpen: swallowed entirely -> 63 LOC (4922-4984), recovered
- spamassassin/Makefile.PL::MY::dist: oversized -> 23 LOC (966-988)
found_functions 938 -> 941 (100% recall), args_exact_match 923 -> 929,
zero regressions across all 31 languages (--all --ci).
Fixes #1517
Co-Authored-By: Claude Sonnet 5 <[email protected]>
squid-protocol
enabled auto-merge (squash)
August 15, 2026 20:42
…omment-strip # Conflicts: # gitgalaxy/standards/language_standards.py # tests/extraction/languages/test_perl.py # tests/golden_master_audit.json # tests/golden_master_zero_dep_audit.json # tests/ruff_audit_baseline.json
| masked_line, masked_literals = self._mask_line_literals(line) | ||
|
|
||
| if lang_id == "perl": | ||
| masked_line = _mask_perl_line(masked_line, masked_literals) |
Contributor
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.
Summary
Fixes #1517.
perl's
#-to-end-of-line comment stripper (prism.py's_strip_single_line_comments) had no awareness of perl's quote-likeoperators (
qq{...},q{...}, etc.) OR of/regex/literals (bare orkeyword-prefixed:
m/.../,s/.../.../, etc.) -- any#characterappearing as literal CONTENT inside either of those, on the same line, was
misread as a real comment start, stripping everything from that
#toend-of-line before
detector.pyever saw it. Confirmed on 3 real corpusfunctions (
language-crucible/data/perl):mojo/Template.pm::_line:return qq{#line @{[shift]} "$name"};--the
#lineright afterqq{is real quote-op content (a perl#linedirective template), wrongly read as a comment, desyncing everything
downstream through end of file.
exiftool/exiftool::FilterArgfileLine:if ($arg =~ /^#/) { # comment lines begin with '#'-- the bare/^#/regex literal's own#misreadas a comment start with no keyword prefix at all, swallowing 1048 lines
instead of ~23 and hiding the real definition of
ReadStayOpenentirely.spamassassin/Makefile.PL::MY::dist:next if $line =~ /^\s*#/;--same mechanism, same bare-regex-with-embedded-
#shape.Fix
Added a perl-gated masking pass in
_strip_single_line_commentsthat runsbefore the
#-delimiter search: brace-delimited quote-ops(
qq{}/q{}/etc, balanced-brace scan with backslash-escape handling) andboth keyword-prefixed (
m/,s/,tr/,y/) and bare/regex/literals(a preceding-token heuristic disambiguates regex-open from division:
=~/!~/(/,/;/{/&&/||or a keyword likeif/unless/while/split/grep/map/returnimmediately before abare
/means regex-open; an identifier/number/)/]means division).Two additional real bugs found and fixed during verification, beyond the
original diagnosis:
prism.py's_restore_masked_literalsused a single-passre.sub,which didn't fully unmask nested literal structures (e.g. a quote inside
s{...}{...}) -- now loops until no__MASK_N__tokens remain.detector.py's_build_brace_safe_streamran its generic quote-shielding pass BEFORE perl's own quote-op/regex shielding, so a quote
inside a regex body could still mispair with an unrelated quote
downstream, corrupting brace-depth counting -- this was the actual
reason
exiftool::FilterArgfileLinewas still swallowing 1000+ lineseven after the prism.py fix alone. Reordered: perl skips the early
generic pass and re-runs it after perl-specific shielding instead.
Verification
Cross-language spot check (python/ruby/shell/powershell, which share the
"line_exclusive" lexical family) confirmed unaffected -- the new masking
pass is strictly gated to
lang_id == "perl".crucible_check.py --mode bothblessed via--update --yes(expectedcascading drift).
audit_check.py --ciclean.Type of change
prism.py,detector.py)Differential Scan target
Perl parser corpus (mojo, exiftool, spamassassin) -- the same files the
issue's measurements came from.
Co-Authored-By: Claude Sonnet 5 [email protected]