Interface Production<T>

All Known Implementing Classes:
Parser, Parser.OrEmpty, Parser.Rule

public sealed interface Production<T> permits Parser<T>, Parser<T>.OrEmpty
A sealed interface representing an abstract production rule that can either be an always-consuming Parser or an optional Parser.OrEmpty.

Useful as a parameter to Parser.sequence() methods, so as to avoid overload explosion.

Since:
10.0
  • Method Details

    • parse

      T parse(String input)
      Parses the entire input string and returns the result. Upon successful return, the input is fully consumed.
      Throws:
      Parser.ParseException - if the input cannot be parsed.
    • parseSkipping

      T parseSkipping(Parser<?> skip, String input)
      Parses the entire input string, ignoring patterns matched by skip, and returns the result.
      Throws:
      Parser.ParseException - if the input cannot be parsed.
    • parseSkipping

      T parseSkipping(CharPredicate charsToSkip, String input)
      Parses the entire input string, ignoring charsToSkip, and returns the result.
      Throws:
      Parser.ParseException - if the input cannot be parsed.
    • matches

      boolean matches(String input)
      Returns true if this production rule matches the entirety of input string.
    • between

      default Parser<T> between(String prefix, String suffix)
      The current production must be enclosed between non-empty prefix and suffix.
    • between

      default Parser<T> between(Parser<?> prefix, Parser<?> suffix)
      The current production must be enclosed between non-empty prefix and suffix.
    • between

      default Parser<T> between(Parser<?> prefix, Parser<?>.OrEmpty suffix)
      The current production must be enclosed between non-empty prefix and suffix that may be empty.
    • between

      default Parser<T> between(Parser<?>.OrEmpty prefix, Parser<?> suffix)
      The current production must be enclosed between prefix that may be empty and suffix that may not be empty.
    • between

      Production<T> between(Parser<?>.OrEmpty prefix, Parser<?>.OrEmpty suffix)
      Returns a production rule that matches this pattern enclosed between prefix and suffix,* both allowed to be empty.

      Note that the Parser and Parser.OrEmpty implementations are re-declared to return the more specific Parser<T> or Parser<T>.OrEmpty subtypes respectively.

    • immediatelyBetween

      default Parser<T> immediatelyBetween(String prefix, String suffix)
      The current production must be immediately enclosed between non-empty prefix and suffix (no skippable characters as specified by parseSkipping() in between). Useful for matching a literal string, such as zeroOrMore(isNot('"')).immediatelyBetween("\"", "\"").
    • then

      <S> Parser<S> then(Parser<S> suffix)
      After matching the current production, proceed to match suffix.
    • then

      <S> Production<S> then(Parser<S>.OrEmpty suffix)
      After matching the current production rule, proceed to match suffix.

      Note that the Parser and Parser.OrEmpty implementations are re-declared to return the more specific Parser<S> or Parser<S>.OrEmpty subtypes respectively.

    • followedBy

      default Parser<T> followedBy(String suffix)
      The current production must be followed by non-empty suffix.
    • followedBy

      Parser<T> followedBy(Parser<?> suffix)
      The current production must be followed by non-empty suffix.
    • followedBy

      <S> Production<T> followedBy(Parser<S>.OrEmpty suffix)
      The current production may optionally be followed by suffix.

      Note that the Parser and Parser.OrEmpty implementations are re-declared to return the more specific Parser<T> or Parser<T>.OrEmpty subtypes respectively.

    • optionallyFollowedBy

      Production<T> optionallyFollowedBy(String suffix)
      Returns an equivalent production except it allows suffix if present.

      Note that the Parser and Parser.OrEmpty implementations are re-declared to return the more specific Parser<T> or Parser<T>.OrEmpty subtypes respectively.

    • optionallyFollowedBy

      Production<T> optionallyFollowedBy(String suffix, Function<? super T, ? extends T> op)
      If this production rule matches, optionally applies the op function if this production is followed by suffix.

      Note that the Parser and Parser.OrEmpty implementations are re-declared to return the more specific Parser<T> or Parser<T>.OrEmpty subtypes respectively.

    • optionallyFollowedBy

      <S> Production<T> optionallyFollowedBy(Parser<S> suffix, BiFunction<? super T, ? super S, ? extends T> op)
      If this production rule matches, optionally matches suffix with the op BiFunction to transform the current production's result.

      Note that the Parser and Parser.OrEmpty implementations are re-declared to return the more specific Parser<T> or Parser<T>.OrEmpty subtypes respectively.