Class LookaheadReader
- java.lang.Object
-
- ca.solostudios.strata.parser.tokenizer.Lookahead<Char>
-
- ca.solostudios.strata.parser.tokenizer.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
Readerone after another. UsingLookahead.next(), upcoming characters can be inspected without consuming (removing) the current one.
-
-
Field Summary
-
Fields inherited from class ca.solostudios.strata.parser.tokenizer.Lookahead
endOfInputIndicator, endReached, itemBuffer
-
-
Constructor Summary
Constructors Constructor Description LookaheadReader(@NotNull java.io.Reader input)Creates a new LookaheadReader for the given Reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected @NotNull CharendOfInput()Creates the end of input indicator item.protected @Nullable Charfetch()Fetches the next item from the stream.java.lang.StringtoString()
-
-
-
Constructor Detail
-
LookaheadReader
public LookaheadReader(@NotNull @NotNull java.io.Reader input)Creates a new LookaheadReader for the given Reader.Internally a
BufferedReaderis 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:
toStringin classjava.lang.Object
-
fetch
@Nullable protected @Nullable Char fetch() throws ParseException
Description copied from class:LookaheadFetches the next item from the stream.- Specified by:
fetchin classLookahead<Char>- Returns:
- the next item in the stream or
nullto 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:LookaheadCreates the end of input indicator item.This method will be only called once, as the indicator is cached.
- Specified by:
endOfInputin classLookahead<Char>- Returns:
- a special item which marks the end of the input
-
-