Skip to content

feat: add {,n} quantifier and fix \p{^Name} negation#35

Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-quantifier-and-property-negation
Draft

feat: add {,n} quantifier and fix \p{^Name} negation#35
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-quantifier-and-property-negation

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

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

What

Add support for {,n} quantifier syntax (Perl 5.34+) and fix \p{^Name} property negation handling.

Why

Two parsing gaps where the module diverges from Perl's actual behavior:

  1. {,n} quantifier — Perl 5.34 added {,n} as shorthand for {0,n}. The parser was treating it as literal text because the handler's regex required at least one digit before the comma.

  2. \p{^Name} negation — Perl allows ^ inside \p{} to negate, equivalent to \P{Name}. The parser was storing ^Name as the type with neg=0, making the negation invisible to programmatic consumers.

How

  • Quantifier: Added a second regex match in the { handler for ,\d+\} pattern, defaulting min to 0. Visual output normalizes to {0,n}.
  • Property: Added ^ stripping in the \p handler with neg=1 flag. Visual normalizes to \P{Name}.

Both normalizations are consistent with existing parser behavior (e.g., (?P<name>) normalizes to (?<name>)).

Testing

  • New test file t/18quantprop.t with 11 subtests covering: basic parsing, different values, lazy/possessive modifiers, groups/classes, round-trips, edge cases, character class context, and \p{^X} vs \P{X} equivalence.
  • Full suite: 1166 tests pass across 21 test files.

🤖 Generated with Claude Code


Quality Report

Changes: 3 files changed, 156 insertions(+), 2 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Two parsing fixes:

1. {,n} quantifier syntax (Perl 5.34+): upper bound only with implicit
   min=0. Previously treated as literal text. Normalizes to {0,n} in
   visual output. Supports lazy ({,n}?) and possessive ({,n}+) modifiers.

2. \p{^Name} caret negation: the ^ prefix inside \p{} is equivalent to
   \P{Name} but the parser was storing "^Name" as the type with neg=0.
   Now correctly strips ^ and sets neg=1, normalizing to \P{Name}.

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