@@ -955,7 +955,7 @@ public final Parser<T> withPostfixes(String operator, UnaryOperator<T> postfixFu
955955 *
956956 * @since 9.5
957957 */
958- public final Parser <T > between (Parser <?>.OrEmpty prefix , Parser <?>.OrEmpty suffix ) {
958+ @ Override public final Parser <T > between (Parser <?>.OrEmpty prefix , Parser <?>.OrEmpty suffix ) {
959959 return prefix .then (this ).followedBy (suffix );
960960 }
961961
@@ -1006,7 +1006,7 @@ public final <R> Parser<R> thenReturn(R result) {
10061006 *
10071007 * @since 10.0
10081008 */
1009- public final <R > Parser <R > then (Grammar <R > next ) {
1009+ @ Override public final <R > Parser <R > then (Parser <R >. OrEmpty next ) {
10101010 return sequence (this , next , (unused , value ) -> value );
10111011 }
10121012
@@ -1038,7 +1038,7 @@ public final Parser<T> suchThat(Predicate<? super T> condition, String name) {
10381038 }
10391039
10401040 /** If this parser matches, continue to match the optional {@code suffix}. */
1041- public final Parser <T > followedBy (Grammar <?> suffix ) {
1041+ public final < S > Parser <T > followedBy (Parser < S >. OrEmpty suffix ) {
10421042 return sequence (this , suffix , (value , unused ) -> value );
10431043 }
10441044
@@ -1057,15 +1057,15 @@ final Parser<T> followedByEof() {
10571057 }
10581058
10591059 /** Returns an equivalent parser except it allows {@code suffix} if present. */
1060- public final Parser <T > optionallyFollowedBy (String suffix ) {
1060+ @ Override public final Parser <T > optionallyFollowedBy (String suffix ) {
10611061 return followedBy (string (suffix ).orElse (null ));
10621062 }
10631063
10641064 /**
10651065 * If this parser matches, optionally applies the {@code op} function if the pattern is followed
10661066 * by {@code suffix}.
10671067 */
1068- public final Parser <T > optionallyFollowedBy (String suffix , Function <? super T , ? extends T > op ) {
1068+ @ Override public final Parser <T > optionallyFollowedBy (String suffix , Function <? super T , ? extends T > op ) {
10691069 return optionalPostfix (string (suffix ).thenReturn (op ::apply ));
10701070 }
10711071
@@ -1083,7 +1083,7 @@ public final Parser<T> optionallyFollowedBy(String suffix, Function<? super T, ?
10831083 *
10841084 * @since 9.5
10851085 */
1086- public final <S > Parser <T > optionallyFollowedBy (
1086+ @ Override public final <S > Parser <T > optionallyFollowedBy (
10871087 Parser <S > suffix , BiFunction <? super T , ? super S , ? extends T > op ) {
10881088 requireNonNull (op );
10891089 return optionalPostfix (suffix .map (s -> p -> op .apply (p , s )));
@@ -1465,7 +1465,7 @@ private OrEmpty(Supplier<? extends T> defaultSupplier) {
14651465 *
14661466 * @since 9.5
14671467 */
1468- public final Parser <T >.OrEmpty between (Parser <?>.OrEmpty prefix , Parser <?>.OrEmpty suffix ) {
1468+ @ Override public final Parser <T >.OrEmpty between (Parser <?>.OrEmpty prefix , Parser <?>.OrEmpty suffix ) {
14691469 return prefix .then (this ).followedBy (suffix );
14701470 }
14711471
@@ -1503,12 +1503,12 @@ public Parser<List<T>>.OrEmpty delimitedBy(String delimiter) {
15031503 }
15041504
15051505 /** After matching the current optional (or zero-or-more) parser, proceed to match {@code suffix}. */
1506- public <S > Parser <S >.OrEmpty then (Parser <S >.OrEmpty suffix ) {
1506+ @ Override public <S > Parser <S >.OrEmpty then (Parser <S >.OrEmpty suffix ) {
15071507 return sequence (this , suffix , (a , b ) -> b );
15081508 }
15091509
15101510 /** The current optional (or zero-or-more) parser may optionally be followed by {@code suffix}. */
1511- public <S > Parser <T >.OrEmpty followedBy (Parser <S >.OrEmpty suffix ) {
1511+ @ Override public <S > Parser <T >.OrEmpty followedBy (Parser <S >.OrEmpty suffix ) {
15121512 return sequence (this , suffix , (a , b ) -> a );
15131513 }
15141514
@@ -1517,10 +1517,36 @@ public <S> Parser<T>.OrEmpty followedBy(Parser<S>.OrEmpty suffix) {
15171517 *
15181518 * @since 9.5
15191519 */
1520- public Parser <T >.OrEmpty optionallyFollowedBy (String suffix ) {
1520+ @ Override public Parser <T >.OrEmpty optionallyFollowedBy (String suffix ) {
15211521 return followedBy (string (suffix ).orElse (null ));
15221522 }
15231523
1524+ /**
1525+ * If this parser matches, optionally applies the {@code op} function if the pattern is followed
1526+ * by {@code suffix}.
1527+ *
1528+ * @since 10.0
1529+ */
1530+ @ Override public final Parser <T >.OrEmpty optionallyFollowedBy (String suffix , Function <? super T , ? extends T > op ) {
1531+ return optionallyFollowedBy (string (suffix ).thenReturn (op ::apply ));
1532+ }
1533+
1534+ /**
1535+ * If this parser matches, optionally matches {@code suffix} with the {@code op} BiFunction
1536+ * to transform the current parser's result.
1537+ *
1538+ * @since 10.0
1539+ */
1540+ @ Override public final <S > Parser <T >.OrEmpty optionallyFollowedBy (
1541+ Parser <S > suffix , BiFunction <? super T , ? super S , ? extends T > op ) {
1542+ requireNonNull (op );
1543+ return optionallyFollowedBy (suffix .map (s -> p -> op .apply (p , s )));
1544+ }
1545+
1546+ private Parser <T >.OrEmpty optionallyFollowedBy (Parser <UnaryOperator <T >> suffix ) {
1547+ return sequence (this , suffix .orElse (identity ()), (operand , op ) -> op .apply (operand ));
1548+ }
1549+
15241550 /**
15251551 * Returns the otherwise equivalent {@code Parser} that will fail instead of returning the
15261552 * default value if empty.
@@ -1678,7 +1704,7 @@ Stream<T> parseToStream(CharInput input, int fromIndex) {
16781704 * input is exhausted or matching failed.
16791705 *
16801706 * <p>Note that unlike {@link #parseToStream(String) parseToStream()}, a matching failure
1681- * terminates the stream without throwing exception.
1707+ * terminates the stream out throwing exception.
16821708 *
16831709 * <p>This allows quick probing without fully parsing it.
16841710 */
0 commit comments