fix: (?'name'...) single-quote capture and bare \g-N backref#41
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: (?'name'...) single-quote capture and bare \g-N backref#41toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
Two bugs where the parser rejected valid Perl regex syntax:
1. (?'name'...) named capture failed because Perl treats ' as a
package separator, so add_handler/can() dispatch couldn't find
the handler. Fixed by handling ' inline in the (? handler.
Visual output preserves single-quote syntax for round-trip fidelity.
2. Bare \g-N (negative relative backref without braces) was rejected
with "Missing braces on \g{}". Perl supports \g-1, \g-2 etc.
Added bare negative-relative matching before the existing \gN path.
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.
What
Fix two cases where the parser rejects valid Perl regex syntax.
Why
(?'name'...)is a standard Perl 5.10+ alternate syntax for named captures (equivalent to(?<name>...)). It was broken because Perl treats'as a package separator in symbol names, soadd_handler("(?'")/can("(?'")installed and looked up the handler in the wrong package.Bare
\g-1(negative relative backref without braces) is valid Perl syntax that was rejected with "Missing braces on \g{}". Only the braced form\g{-1}worked.How
(?'name'...): Handle the single-quote case inline in the(?handler, before thecan()dispatch. Removed the deadadd_handler("(?'"...)registration. Thenamed_openconstructor now accepts an optional prefix arg to render(?'name'instead of(?<name>inraw/visual/qr()output.\g-N: Added a match for-\d+before the existing\d+match in the\ghandler, with the same resolution logic as the braced form.Testing
t/18single_quote_capture.t: parsing, visual output, tree structure, round-trip, mixed syntax, qr() output, error cases🤖 Generated with Claude Code
Quality Report
Changes: 4 files changed, 139 insertions(+), 19 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline