Skip to content

fix: detect readline with variable filehandle after block#372

Draft
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-221
Draft

fix: detect readline with variable filehandle after block#372
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-221

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a <$fh> readline operator is preceded by a map/grep/sort block, PPI incorrectly tokenizes it as two separate < and > operators instead of a single PPI::Token::QuoteLike::Readline. The root cause is that the regex in Whitespace.pm that disambiguates < after a closing brace } only matched bareword filehandles (<FILE>) but not variable filehandles (<$fh>).

Fixes #221

Changes

  • Added \$? to the readline detection regex in Token/Whitespace.pm so it matches both <FILE> and <$fh> patterns after a closing brace
  • Added regression test covering map, grep, and sort blocks followed by <$fh> and <FILE>

Test plan

  • New regression test 52_readline_after_block verifies correct tokenization of <$fh> after map/grep/sort blocks
  • Full test suite (69 files, 53593 tests) passes with no regressions
  • Manual verification that $foo->{bar} < 2 still correctly tokenizes < as an operator

Generated by Kōan /fix


Quality Report

Changes: 5 files changed, 76 insertions(+), 3 deletions(-)

Code scan: clean

Tests: skipped

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

toddr-bot and others added 2 commits April 26, 2026 21:30
Reproduces GitHub issue #221 where <$fh> after a block like
map { $_ } is incorrectly tokenized as separate < and > operators
instead of PPI::Token::QuoteLike::Readline.

$TODO: tests fail until the tokenizer fix is applied.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The regex that disambiguates < as operator vs readline after a closing
brace only matched bareword filehandles like <FILE>. Adding \$? to the
pattern lets it also match variable filehandles like <$fh>.

Fixes #221

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Readline operator is not properly detected when preceded by a map block

1 participant