Package com.blackrook.json.struct
Class Lexer.ReaderStack
java.lang.Object
com.blackrook.json.struct.Lexer.ReaderStack
- Enclosing class:
- Lexer
This holds a series of
Reader
streams such that the stream on top is the current active stream.
This was separated out of Lexer
to mix different Lexers on one stack (different lexers, same stream).
It is the user's responsibility to pop()
streams off of the stack when they reach an end.- Author:
- Matthew Tropiano
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Stream encapsulation of a single named Reader. -
Constructor Summary
ConstructorDescriptionCreates a new empty ReaderStack.ReaderStack
(String name, Reader reader) Creates a new ReaderStack. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
final int
final String
final boolean
isEmpty()
final Lexer.ReaderStack.Stream
peek()
Gets the reference to the topmost (current) stream.final Lexer.ReaderStack.Stream
pop()
Pops aLexer.ReaderStack.Stream
off of the top of this stack.final void
Pushes another reader onto the stack.final int
readChar()
Reads the next character.final int
size()
-
Constructor Details
-
ReaderStack
public ReaderStack()Creates a new empty ReaderStack. -
ReaderStack
Creates a new ReaderStack.- Parameters:
name
- the name to give the first reader.reader
- the reader itself (assumed open).
-
-
Method Details
-
push
Pushes another reader onto the stack.- Parameters:
name
- the name to give this reader.reader
- the reader itself (assumed open).
-
peek
Gets the reference to the topmost (current) stream.- Returns:
- the topmost stream.
-
pop
Pops aLexer.ReaderStack.Stream
off of the top of this stack. The stream is closed automatically.- Returns:
- the removed
Lexer.ReaderStack.Stream
, or null if empty. - See Also:
-
getCurrentStreamName
- Returns:
- the current stream name, or null if empty.
- See Also:
-
getCurrentLineNumber
public final int getCurrentLineNumber()- Returns:
- the current line number, or -1 if empty.
- See Also:
-
getCurrentLineCharacterIndex
public final int getCurrentLineCharacterIndex()- Returns:
- the current line number, or -1 if empty.
- See Also:
-
size
public final int size()- Returns:
- the amount of readers in the stack.
-
isEmpty
public final boolean isEmpty()- Returns:
- if there are no readers in the stack.
-
readChar
Reads the next character.- Returns:
- the character read, or null if end of current stream.
- Throws:
IOException
- if a line cannot be read by the topmost Reader.
-