Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Perl(PCRE) named and unnamed group capturing order #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

CIAvash
Copy link

@CIAvash CIAvash commented May 10, 2021

In other words maintain the order of capture groups. With the MaintainCaptureOrder regexp option.

I also added inline option o. It's useful if you only have access to the pattern, but not the regex. But it only is useful if used at the start of the pattern, I couldn't find a way to prevent it from being used elsewhere.

I've never liked nor have been good with bitwise operations. So I don't know if I should've picked another number.

In other words maintain the order of capture groups.
@dlclark
Copy link
Owner

dlclark commented May 11, 2021

Thanks for submitting this! It'll take me a bit to review and gather my thoughts on it.

Copy link
Owner

@dlclark dlclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On first pass I have a few questions, it'd be great to get your perspective on them.

regexp.go Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
syntax/parser.go Outdated Show resolved Hide resolved
syntax/parser.go Show resolved Hide resolved
@@ -386,7 +417,11 @@ func (p *parser) countCaptures() error {
}
} else {
if !p.useOptionN() && !p.ignoreNextParen {
p.noteCaptureSlot(p.consumeAutocap(), pos)
if p.useMaintainCaptureOrder() {
p.noteCaptureName(fmt.Sprint(p.autocap), pos)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not consumeAutocap() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because consumeAutocap is called inside noteCaptureName when MaintainCaptureOrder is enabled.

Does this need a comment somewhere?

syntax/parser.go Show resolved Hide resolved
regexp_MaintainCaptureOrder_test.go Show resolved Hide resolved
- Document MaintainCaptureOrder option
- Use return in `assignNameSlots` and remove else
- Add test with MaintainCaptureOrder not provided
- Change the MaintainCaptureOrder value to `0x0400`
- Remove the `o` inline option
- Add comment to explain why `autocap` is consumed
@yywing
Copy link

yywing commented Jul 16, 2021

Is there anyway get named group?

like (1)(?<aa>2)

I want get aa only.

@CIAvash
Copy link
Author

CIAvash commented Jul 16, 2021

@yywing Don't know why you asked that question here, as it's not relevant to the pull request. But you can do match.GroupByName(`aa`).

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