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 ofReader
streams such that the stream on top is the current active stream. This was separated out ofLexer
to 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 class
Lexer.ReaderStack.Stream
Stream 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 int
getCurrentLineCharacterIndex()
int
getCurrentLineNumber()
String
getCurrentStreamName()
boolean
isEmpty()
Lexer.ReaderStack.Stream
peek()
Gets the reference to the topmost (current) stream.Lexer.ReaderStack.Stream
pop()
Pops aLexer.ReaderStack.Stream
off of the top of this stack.void
push(String name, Reader reader)
Pushes another reader onto the stack.int
readChar()
Reads the next character.int
size()
-
-
-
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.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:
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 IOException
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.
-
-