fix: recognize regex after map/grep block (RT #75921) - #426
Draft
toddr-bot wants to merge 2 commits into
Draft
Conversation
PPI parses `map { 0 } /z/` with `/z/` as two division operators instead
of a Regexp::Match token. Add TODO-marked tests that demonstrate the
expected behavior for both map and grep with block arguments.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When `/` follows a closing `}` that belongs to a map/grep block,
the tokenizer now walks backward through the token stream to find
the matching `{` and checks whether a MATCHWORD (map, grep, etc.)
precedes it. This correctly identifies `map { 0 } /z/` as containing
a Regexp::Match rather than two division operators.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
When
/regex/follows amap { ... }orgrep { ... }block, PPI incorrectly tokenized the/characters as division operators instead of recognizing the pattern as aPPI::Token::Regexp::Match. This happened because the tokenizer's/-disambiguation logic only checked for MATCHWORD keywords as the immediately previous significant token, missing the case where a block intervenes.The fix walks backward through the token stream when a closing
}precedes/, finds the matching{, and checks whether a MATCHWORD (map,grep,if,unless,split,return) precedes that opening brace.Fixes #67
Changes
Whitespace.pm's/handler to detect MATCHWORD keywords before a closing block52_regex_after_map_block.code/.dump) covering bothmapandgrepwith block argumentsTest plan
map { 0 } /z/,grep { 0 } /z/, andmap { 0 } /z/inow parse/z/asRegexp::Matchmap /bar/, @foo(non-block),$x = $y / $z / 2(division),do { 1 } / 2(division after non-MATCHWORD)Generated by Kōan /fix
Quality Report
Changes: 5 files changed, 75 insertions(+), 2 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline