Class LookaheadReader


  • public class LookaheadReader
    extends Lookahead<Char>
    An efficient reader of character streams, reading character by character and supporting lookaheads.

    Helps to read characters from a Reader one after another. Using Lookahead.next(), upcoming characters can be inspected without consuming (removing) the current one.

    • Constructor Detail

      • LookaheadReader

        public LookaheadReader​(@NotNull
                               @NotNull java.io.Reader input)
        Creates a new LookaheadReader for the given Reader.

        Internally a BufferedReader is used to efficiently read single characters. The given reader will not be closed by this class.

        Parameters:
        input - the reader to draw the input from
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fetch

        @Nullable
        protected @Nullable Char fetch()
                                throws ParseException
        Description copied from class: Lookahead
        Fetches the next item from the stream.
        Specified by:
        fetch in class Lookahead<Char>
        Returns:
        the next item in the stream or null to indicate that the end was reached
        Throws:
        ParseException - If there is an exception during parsing.
      • endOfInput

        @NotNull
        protected @NotNull Char endOfInput()
        Description copied from class: Lookahead
        Creates the end of input indicator item.

        This method will be only called once, as the indicator is cached.

        Specified by:
        endOfInput in class Lookahead<Char>
        Returns:
        a special item which marks the end of the input