Skip to content

feat: add (?[...]) extended character class support#31

Merged
toddr merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/extended-charclass-syntax
Mar 27, 2026
Merged

feat: add (?[...]) extended character class support#31
toddr merged 1 commit into
cpan-authors:mainfrom
toddr-bot:koan.toddr.bot/extended-charclass-syntax

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

What

Add support for parsing (?[...]) extended character class syntax introduced in Perl 5.18.

Why

This was the last significant modern Perl regex feature missing from the parser. Extended character classes enable set operations (union, intersection, subtraction, complement) on character classes — widely used in Unicode-aware code. Without this, the parser would choke on any regex containing (?[...]).

How

  • New (?[ handler in Handlers.pm that matches balanced content (handling nested [...], (...), \ escapes, and # comments)
  • New charclass_expr object type in Objects.pm — a leaf node storing the expression content as an opaque string, consistent with how (?{code}) blocks are handled
  • Expression content is faithfully preserved for visual() round-trip stability

Testing

  • 68 new tests in t/17extcharclass.t covering:
    • All set operators: +, &, -, ^, !
    • Nested traditional character classes
    • Unicode properties
    • Parenthesized subexpressions
    • Escape sequences
    • Tree structure and data accessor
    • Embedding in larger patterns (anchors, quantifiers, alternation)
    • Round-trip stability (parse → visual → re-parse → visual)
    • Comments inside extended classes
  • Full suite: 1114 tests pass across 20 files

🤖 Generated with Claude Code

Parse extended character classes with set operations (union +,
intersection &, subtraction -, symmetric difference ^, complement !).
Expression content stored as opaque string, consistent with how
(?{code}) blocks are handled. Includes 68 tests covering operators,
nested classes, Unicode properties, round-trip stability, and
embedding in larger patterns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@atoomic atoomic marked this pull request as ready for review March 27, 2026 02:26
@toddr toddr merged commit 7dce9eb into cpan-authors:main Mar 27, 2026
20 checks passed
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.

3 participants