Package com.blackrook.expression.struct
Class Lexer.ReaderStack
- java.lang.Object
-
- com.blackrook.expression.struct.Lexer.ReaderStack
-
- Enclosing class:
- Lexer
public static class Lexer.ReaderStack extends Object
This holds a series ofReaderstreams such that the stream on top is the current active stream. This was separated out ofLexerto mix different Lexers on one stack (different lexers, same stream). It is the user's responsibility topop()streams off of the stack when they reach an end.- Author:
- Matthew Tropiano
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classLexer.ReaderStack.StreamStream encapsulation of a single named Reader.
-
Constructor Summary
Constructors Constructor Description ReaderStack()Creates a new empty ReaderStack.ReaderStack(String name, Reader reader)Creates a new ReaderStack.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCurrentLineCharacterIndex()intgetCurrentLineNumber()StringgetCurrentStreamName()booleanisEmpty()Lexer.ReaderStack.Streampeek()Gets the reference to the topmost (current) stream.Lexer.ReaderStack.Streampop()Pops aLexer.ReaderStack.Streamoff of the top of this stack.voidpush(String name, Reader reader)Pushes another reader onto the stack.intreadChar()Reads the next character.intsize()
-
-
-
Method Detail
-
push
public final void push(String name, Reader reader)
Pushes another reader onto the stack.- Parameters:
name- the name to give this reader.reader- the reader itself (assumed open).
-
peek
public final Lexer.ReaderStack.Stream peek()
Gets the reference to the topmost (current) stream.- Returns:
- the topmost stream.
-
pop
public final Lexer.ReaderStack.Stream pop()
Pops aLexer.ReaderStack.Streamoff of the top of this stack. The stream is closed automatically.- Returns:
- the removed
Lexer.ReaderStack.Stream, or null if empty. - See Also:
isEmpty()
-
getCurrentStreamName
public final String getCurrentStreamName()
- Returns:
- the current stream name, or null if empty.
- See Also:
isEmpty()
-
getCurrentLineNumber
public final int getCurrentLineNumber()
- Returns:
- the current line number, or -1 if empty.
- See Also:
isEmpty()
-
getCurrentLineCharacterIndex
public final int getCurrentLineCharacterIndex()
- Returns:
- the current line number, or -1 if empty.
- See Also:
isEmpty()
-
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
public final int readChar() throws IOExceptionReads 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.
-
-