Skip to content

Commit 828b71d

Browse files
committed
hide optionallyFollowedBy(Parser<UnaryOperator>). Not consistent with the other members of the overload family
1 parent eb0f03c commit 828b71d

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

dot-parse/src/main/java/com/google/common/labs/parse/OperatorTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private static final class Infixl<T> extends Binary<T> {
195195

196196
private static final class Infixn<T> extends Binary<T> {
197197
@Override public Parser<T> makeExpressionParser(Parser<T> operand) {
198-
return operand.optionallyFollowedBy(opWithRightHandSide(operand));
198+
return operand.optionalPostfix(opWithRightHandSide(operand));
199199
}
200200
}
201201

dot-parse/src/main/java/com/google/common/labs/parse/Parser.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import static com.google.mu.util.stream.MoreStreams.whileNotNull;
2323
import static java.util.Arrays.stream;
2424
import static java.util.Objects.requireNonNull;
25-
import static java.util.function.Function.identity;
25+
import static java.util.function.UnaryOperator.identity;
2626
import static java.util.stream.Collectors.collectingAndThen;
2727
import static java.util.stream.Collectors.counting;
2828
import static java.util.stream.Collectors.joining;
@@ -763,18 +763,11 @@ public final Parser<T> optionallyFollowedBy(String suffix) {
763763
* by {@code suffix}.
764764
*/
765765
public final Parser<T> optionallyFollowedBy(String suffix, Function<? super T, ? extends T> op) {
766-
return optionallyFollowedBy(string(suffix).thenReturn(op::apply));
766+
return optionalPostfix(string(suffix).thenReturn(op::apply));
767767
}
768768

769-
/**
770-
* Returns an equivalent parser except it will optionally apply the unary operator resulting from
771-
* {@code suffix}.
772-
*/
773-
public final Parser<T> optionallyFollowedBy(Parser<? extends UnaryOperator<T>> suffix) {
774-
return sequence(
775-
this,
776-
suffix.orElse(null),
777-
(operand, operator) -> operator == null ? operand : operator.apply(operand));
769+
final Parser<T> optionalPostfix(Parser<UnaryOperator<T>> suffix) {
770+
return sequence(this, suffix.orElse(identity()), (operand, op) -> op.apply(operand));
778771
}
779772

780773
/** A form of negative lookahead such that the match is rejected if followed by {@code suffix}. */

dot-parse/src/test/java/com/google/common/labs/parse/ParserTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4268,7 +4268,7 @@ static Parser<ResourceNamePattern> parser() {
42684268
subpath)
42694269
.atLeastOnceDelimitedBy("/")
42704270
.map(ResourceNamePattern::new)
4271-
.optionallyFollowedBy(revision.map(v -> pattern -> pattern.withRevision(v)));
4271+
.optionalPostfix(revision.map(v -> pattern -> pattern.withRevision(v)));
42724272
}
42734273

42744274
static ResourceNamePattern parse(String path) {

0 commit comments

Comments
 (0)