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
Reader
one 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 Char
endOfInput()
Creates the end of input indicator item.protected @Nullable Char
fetch()
Fetches the next item from the stream.java.lang.String
toString()
-
-
-
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 classjava.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 classLookahead<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 classLookahead<Char>
- Returns:
- a special item which marks the end of the input
-
-