Class Lexer.ReaderStack

java.lang.Object
net.mtrop.doom.struct.Lexer.ReaderStack
Enclosing class:
Lexer

public static class Lexer.ReaderStack extends Object
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
  • Constructor Details

    • ReaderStack

      public ReaderStack()
      Creates a new empty ReaderStack.
    • ReaderStack

      public ReaderStack(String name, Reader reader)
      Creates a new ReaderStack.
      Parameters:
      name - the name to give the first reader.
      reader - the reader itself (assumed open).
  • Method Details

    • 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 a Lexer.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

      public final String 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

      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.