stefanvodita commented on code in PR #12462:
URL: https://github.com/apache/lucene/pull/12462#discussion_r1290149550
##########
lucene/core/src/java/org/apache/lucene/util/automaton/RegExp.java:
##########
@@ -1067,22 +1071,44 @@ private boolean check(int flag) {
}
final RegExp parseUnionExp() throws IllegalArgumentException {
- RegExp e = parseInterExp();
- if (match('|')) e = makeUnion(flags, e, parseUnionExp());
- return e;
+ return iterativeParseExp(this::parseInterExp, () -> match('|'),
RegExp::makeUnion);
}
final RegExp parseInterExp() throws IllegalArgumentException {
- RegExp e = parseConcatExp();
- if (check(INTERSECTION) && match('&')) e = makeIntersection(flags, e,
parseInterExp());
- return e;
+ return iterativeParseExp(
+ this::parseConcatExp, () -> check(INTERSECTION) && match('&'),
RegExp::makeIntersection);
}
final RegExp parseConcatExp() throws IllegalArgumentException {
- RegExp e = parseRepeatExp();
- if (more() && !peek(")|") && (!check(INTERSECTION) || !peek("&")))
- e = makeConcatenation(flags, e, parseConcatExp());
- return e;
+ return iterativeParseExp(
+ this::parseRepeatExp,
+ () -> (more() && !peek(")|") && (!check(INTERSECTION) || !peek("&"))),
+ RegExp::makeConcatenation);
+ }
+
+ /**
+ * Custom Functional Interface for a Supplying methods with signature of
RegExp(int int1, RegExp
+ * exp1, RegExp exp2)
+ */
+ @FunctionalInterface
+ private interface MakeRegexGroup {
+ RegExp get(int int1, RegExp exp1, RegExp exp2);
+ }
+
+ final RegExp iterativeParseExp(
+ Supplier<RegExp> gather, BooleanSupplier stop, MakeRegexGroup reduce)
+ throws IllegalArgumentException {
+ Deque<RegExp> regExpStack = new ArrayDeque<>();
Review Comment:
Good point! In these cases, `reduce` is an associative function. If we do
this, maybe we can rename it to `associativeReduce` or something similar to
make this extra assumption obvious.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]