33import java .util .function .BiFunction ;
44import java .util .function .Function ;
55
6+ import com .google .common .labs .parse .Parser .OrEmpty ;
67import com .google .common .labs .parse .Parser .ParseException ;
78import com .google .mu .util .CharPredicate ;
89
910/**
10- * A sealed interface that can either be an always-consuming {@link Parser}
11- * or an optional {@link Parser.OrEmpty}. Useful as a parameter to {@code Parser.sequence()}
12- * methods, so that we can avoid exponential number of overloads.
11+ * A sealed interface representing an abstract production rule that can either be an
12+ * always-consuming {@link Parser} or an optional {@link Parser.OrEmpty}.
13+ *
14+ * <p>Useful as a parameter to {@code Parser.sequence()} methods, so as to avoid exponential
15+ * number of overloads.
1316 *
1417 * @since 10.0
1518 */
16- public sealed interface Grammar <T > permits Parser , Parser . OrEmpty {
19+ public sealed interface Production <T > permits Parser , OrEmpty {
1720
1821 /**
1922 * Parses the entire input string and returns the result. Upon successful return, the {@code
@@ -39,15 +42,15 @@ public sealed interface Grammar<T> permits Parser, Parser.OrEmpty {
3942 */
4043 T parseSkipping (CharPredicate charsToSkip , String input );
4144
42- /** Returns true if this grammar matches the entirety of {@code input} string. */
45+ /** Returns true if this production matches the entirety of {@code input} string. */
4346 boolean matches (String input );
4447
45- /** The current grammar must be enclosed between non-empty {@code prefix} and {@code suffix}. */
48+ /** The current production must be enclosed between non-empty {@code prefix} and {@code suffix}. */
4649 default Parser <T > between (String prefix , String suffix ) {
4750 return between (Parser .string (prefix ), Parser .string (suffix ));
4851 }
4952
50- /** The current grammar must be enclosed between non-empty {@code prefix} and {@code suffix}. */
53+ /** The current production must be enclosed between non-empty {@code prefix} and {@code suffix}. */
5154 default Parser <T > between (Parser <?> prefix , Parser <?> suffix ) {
5255 return Parser .sequence (prefix , this , (p , t ) -> t ).followedBy (suffix );
5356 }
@@ -56,13 +59,13 @@ default Parser<T> between(Parser<?> prefix, Parser<?> suffix) {
5659 * Returns a parser that matches {@code this} pattern enclosed between {@code prefix} and {@code suffix},
5760 * both allowed to be empty.
5861 *
59- * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are declared to return the more specific
60- * {@code Parser<T>} or {@code Parser<T>.OrEmpty} subtypes respectively.
62+ * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are re- declared to
63+ * return the more specific {@code Parser<T>} or {@code Parser<T>.OrEmpty} subtypes respectively.
6164 */
62- Grammar <T > between (Parser <?>.OrEmpty prefix , Parser <?>.OrEmpty suffix );
65+ Production <T > between (Parser <?>.OrEmpty prefix , Parser <?>.OrEmpty suffix );
6366
6467 /**
65- * The current grammar must be <em>immediately</em> enclosed between
68+ * The current production must be <em>immediately</em> enclosed between
6669 * non-empty {@code prefix} and {@code suffix} (no skippable characters as specified by {@link
6770 * #parseSkipping parseSkipping()} in between). Useful for matching a literal string, such as
6871 * {@code zeroOrMore(isNot('"')).immediatelyBetween("\"", "\"")}.
@@ -72,7 +75,7 @@ default Parser<T> immediatelyBetween(String prefix, String suffix) {
7275 }
7376
7477 /**
75- * After matching the current grammar , proceed to match {@code suffix}.
78+ * After matching the current production , proceed to match {@code suffix}.
7679 */
7780 default <S > Parser <S > then (Parser <S > suffix ) {
7881 return Parser .sequence (Parser .maybeZeroWidth (this ), suffix , (a , b ) -> b );
@@ -81,53 +84,53 @@ default <S> Parser<S> then(Parser<S> suffix) {
8184 /**
8285 * After matching the current optional (or zero-or-more) parser, proceed to match {@code suffix}.
8386 *
84- * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are declared to
87+ * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are re- declared to
8588 * return the more specific {@code Parser<S>} or {@code Parser<S>.OrEmpty} subtypes respectively.
8689 */
87- <S > Grammar <S > then (Parser <S >.OrEmpty suffix );
90+ <S > Production <S > then (Parser <S >.OrEmpty suffix );
8891
89- /** The current grammar must be followed by non-empty {@code suffix}. */
92+ /** The current production must be followed by non-empty {@code suffix}. */
9093 default Parser <T > followedBy (String suffix ) {
9194 return followedBy (Parser .string (suffix ));
9295 }
9396
94- /** The current grammar must be followed by non-empty {@code suffix}. */
97+ /** The current production must be followed by non-empty {@code suffix}. */
9598 default Parser <T > followedBy (Parser <?> suffix ) {
9699 return Parser .sequence (Parser .maybeZeroWidth (this ), suffix , (a , b ) -> a );
97100 }
98101
99102 /**
100- * The current grammar may optionally be followed by {@code suffix}.
103+ * The current production may optionally be followed by {@code suffix}.
101104 *
102- * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are declared to
105+ * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are re- declared to
103106 * return the more specific {@code Parser<T>} or {@code Parser<T>.OrEmpty} subtypes respectively.
104107 */
105- <S > Grammar <T > followedBy (Parser <S >.OrEmpty suffix );
108+ <S > Production <T > followedBy (Parser <S >.OrEmpty suffix );
106109
107110 /**
108- * Returns an equivalent grammar except it allows {@code suffix} if present.
111+ * Returns an equivalent production except it allows {@code suffix} if present.
109112 *
110- * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are declared to
113+ * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are re- declared to
111114 * return the more specific {@code Parser<T>} or {@code Parser<T>.OrEmpty} subtypes respectively.
112115 */
113- Grammar <T > optionallyFollowedBy (String suffix );
116+ Production <T > optionallyFollowedBy (String suffix );
114117
115118 /**
116- * If this parser matches, optionally applies the {@code op} function if this grammar is followed
119+ * If this parser matches, optionally applies the {@code op} function if this production is followed
117120 * by {@code suffix}.
118121 *
119- * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are declared to
122+ * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are re- declared to
120123 * return the more specific {@code Parser<T>} or {@code Parser<T>.OrEmpty} subtypes respectively.
121124 */
122- Grammar <T > optionallyFollowedBy (String suffix , Function <? super T , ? extends T > op );
125+ Production <T > optionallyFollowedBy (String suffix , Function <? super T , ? extends T > op );
123126
124127 /**
125- * If this grammar matches, optionally matches {@code suffix} with the {@code op} BiFunction
126- * to transform the current grammar 's result.
128+ * If this production matches, optionally matches {@code suffix} with the {@code op} BiFunction
129+ * to transform the current production 's result.
127130 *
128- * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are declared to
131+ * <p>Note that the {@link Parser} and {@link Parser.OrEmpty} implementations are re- declared to
129132 * return the more specific {@code Parser<T>} or {@code Parser<T>.OrEmpty} subtypes respectively.
130133 */
131- <S > Grammar <T > optionallyFollowedBy (
134+ <S > Production <T > optionallyFollowedBy (
132135 Parser <S > suffix , BiFunction <? super T , ? super S , ? extends T > op );
133136}
0 commit comments