Skip to content

fix: accept /p (preserve) flag in (?p:...) inline syntax#51

Draft
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-p-flag-support
Draft

fix: accept /p (preserve) flag in (?p:...) inline syntax#51
toddr-bot wants to merge 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-p-flag-support

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

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

What

Accept the /p (preserve) flag in inline (?p:...) and (?p) syntax, matching Perl's behavior.

Why

The parser rejected (?p:x) with "Sequence (?p...) not recognized" because the (?p handler intercepted p before the flag processing loop. Perl 5.10+ accepts /p as a valid inline modifier (it enables ${^PREMATCH}, ${^MATCH}, ${^POSTMATCH}).

How

  • Modified the (? handler dispatch to only route to (?p when followed by { (for deprecated (?p{...}) logical syntax)
  • Added FLAG_p registration matching g/c/o pattern — returns 0x0 (no-op), stripped from visual output
  • Perl-accurate warning: (?-p) warns, (?p) is silent
  • Safe when called via regex() API (no crash on uninitialized Rx)

Testing

  • 11 new test assertions across t/11errors.t and t/10roundtrip.t
  • Full test suite passes (676+ tests)
  • Verified: (?p:x), (?-p:x), (?pi:x), (?p), (?p{...}), (?P<name>...) all behave correctly

🤖 Generated with Claude Code


Quality Report

Changes: 4 files changed, 25 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The /p flag (preserve match vars, Perl 5.10+) was rejected by the
parser because the (?p handler intercepted 'p' before it could reach
the flag processing loop. Fix: only dispatch to (?p handler when
followed by { (for deprecated (?p{...}) logical syntax); otherwise
let 'p' fall through to flag processing like g/c/o.

Matches Perl's behavior: (?p) is silently accepted, (?-p) warns.
The flag is a no-op (returns 0x0) and stripped from visual output.

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.

1 participant