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

Rewrite (?:|xyz) and (?:xyz|) to (?:xyz)?. #259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

katef
Copy link
Owner

@katef katef commented Sep 21, 2020

This helps a little for rendering out to more natural regexp syntax.

For example:

; ./build/bin/re -r pcre -bpl pcre '(?:a|)(?:|xyz)'
a?(?:xyz)?

@katef katef force-pushed the kate/rewrite-to-optional-alts branch from f513fae to 35cbb57 Compare September 21, 2020 05:08
@@ -317,6 +317,30 @@ rewrite_alt(struct ast_expr *n, enum re_flags flags)
return 1;
}

if (n->u.alt.count == 2) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

@hvdijk points out that this would also apply for n > 2, which I hadn't thought of.

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.

None yet

1 participant