Skip to content

fix: qr() emits hex escapes for \N{NAME} portability#46

Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-nchar-qr-portability
Draft

fix: qr() emits hex escapes for \N{NAME} portability#46
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-nchar-qr-portability

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

What

qr() now emits \x{HH} hex escapes for \N{NAME} nodes instead of the literal \N{NAME} form.

Why

\N{NAME} must be resolved by Perl's lexer at compile time — it cannot appear in a runtime-compiled regex pattern. The parser already resolves named characters to their code points at parse time via nchar(), but the qr() method was re-emitting the \N{NAME} source form, making the compiled pattern unusable on all Perl versions.

How

Added qr() overrides to exact and anyof_char objects that detect \N{...} in the visual form and emit \x{HH} hex escapes using the already-resolved character data. visual() is unchanged — it still shows \N{NAME} for human readability.

Testing

  • 6 new tests in t/99misc.t covering exact nodes, character classes, compilation, and matching
  • \N{LATIN SMALL LETTER A}qr: (?^:\x{61})
  • [\N{LATIN SMALL LETTER A}-\N{LATIN SMALL LETTER Z}]qr: (?^:[\x{61}-\x{7A}])
  • All 1161 existing tests pass

🤖 Generated with Claude Code

\N{NAME} must be resolved by Perl's lexer at compile time. When the
parser emitted \N{NAME} literally in qr() output, the resulting pattern
could not be compiled as a runtime regex on any Perl version. Since the
parser already resolves named characters at parse time via nchar(), the
fix is to emit \x{HH} hex escapes in qr() while preserving \N{NAME}
in visual() for human-readable display.

Fixes both exact nodes and anyof_char (character class) nodes.

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