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

Named group support. #49

Merged
merged 4 commits into from
Apr 2, 2019
Merged

Named group support. #49

merged 4 commits into from
Apr 2, 2019

Conversation

sjamesr
Copy link
Contributor

@sjamesr sjamesr commented Mar 5, 2018

This changes the parser to annotate the returned Regexp with information
about named capture groups. During compliation, this information is
passed along to the RE2 instance and thence to the Matcher.

@sjamesr sjamesr changed the title Named branch support. Named group support. Mar 5, 2018
@sjamesr sjamesr requested a review from alandonovan March 5, 2018 00:49
@@ -980,6 +983,7 @@ private Regexp parseInternal() throws PatternSyntaxException {
if (n != 1) {
throw new PatternSyntaxException(ERR_MISSING_PAREN, wholeRegexp);
}
stack.get(0).namedGroups = namedGroups;

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure it's wrong, just different from the C++ or Scala impls of RE2. The approach in my change appears to be similar to that in the Java SDKs, see http://www.docjar.com/html/api/java/util/regex/Pattern.java.html around line 2800.

Choose a reason for hiding this comment

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

@sjamesr you cannot look at the code in OpenJDK. It's Licensed under GPL. This project is Licensed under this custom License. https://github.com/google/re2j/blob/master/LICENSE

@MasseGuillaume
Copy link

@sjamesr
Copy link
Contributor Author

sjamesr commented Mar 5, 2018

Added appendReplacement support, please take another look.

assertEquals(-1, m.start("nomatch"));
assertEquals(-1, m.end("nomatch"));
assertEquals("whatbbarrrrreverbag",
appendReplacement(m, "what$2ever${bag}"));

Choose a reason for hiding this comment

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

This test is not using the named groups <baz> or <foo> above.

@sjamesr sjamesr force-pushed the add_named_groups branch 2 times, most recently from 0c20b6c to b5f9533 Compare April 29, 2018 14:32
@sjamesr sjamesr force-pushed the add_named_groups branch 2 times, most recently from 3b94f3e to 384da93 Compare May 26, 2018 08:07
@google google deleted a comment from coveralls May 26, 2018
@jarcec
Copy link

jarcec commented Sep 13, 2018

I just wanted to mention that I would love to see support for named groups in RE2J. Would be awesome this pull request could be finished and merged :-)

@sjamesr
Copy link
Contributor Author

sjamesr commented Sep 13, 2018 via email

@jarcec
Copy link

jarcec commented Sep 13, 2018

I sadly do not know the internals, so I can't help much with the actual review myself :-(

sjamesr and others added 4 commits April 2, 2019 08:59
This changes the parser to annotate the returned Regexp with information
about named capture groups. During compliation, this information is
passed along to the RE2 instance and thence to the Matcher.

The parser will throw PatternSyntaxException if duplicate group names
are specified.
@sjamesr sjamesr merged commit c886835 into google:master Apr 2, 2019
@jarcec
Copy link

jarcec commented Apr 2, 2019

Thank you @sjamesr for merging this change! I’m looking forward to take advantage of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants