Class 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 Detail

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