Class LookaheadStream<T>

java.lang.Object
org.antlr.runtime.misc.FastQueue<T>
org.antlr.runtime.misc.LookaheadStream<T>
Direct Known Subclasses:
CommonTreeNodeStream

public abstract class LookaheadStream<T> extends FastQueue<T>
A lookahead queue that knows how to mark/release locations in the buffer for backtracking purposes. Any markers force the FastQueue superclass to keep all tokens until no more markers; then can reset to avoid growing a huge buffer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Returned by nextElement upon end of stream; we add to buffer also
    protected int
    Set to buffer index of eof when nextElement returns eof
    protected int
    Track the last mark() call result value for use in rewind().
    protected int
    tracks how deep mark() calls are nested
    static final int
     

    Fields inherited from class org.antlr.runtime.misc.FastQueue

    data, p
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Make sure we have at least one element to remove, even if EOF
    void
    fill(int n)
    add n elements to buffer
     
    int
     
    protected Object
    LB(int k)
    Look backwards k nodes
    LT(int k)
     
    int
     
    abstract T
    Implement nextElement to supply a stream of elements to this lookahead buffer.
    void
    release(int marker)
     
    Get and remove first element in queue; override FastQueue.remove()
    void
     
    void
     
    void
    rewind(int marker)
     
    void
    seek(int index)
    Seek to a 0-indexed position within data buffer.
    int
    Size of entire stream is unknown; we only know buffer size from FastQueue
    void
    sync(int need)
    Make sure we have 'need' elements from current position p.

    Methods inherited from class org.antlr.runtime.misc.FastQueue

    add, clear, get, head, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • UNINITIALIZED_EOF_ELEMENT_INDEX

      public static final int UNINITIALIZED_EOF_ELEMENT_INDEX
      See Also:
    • eofElementIndex

      protected int eofElementIndex
      Set to buffer index of eof when nextElement returns eof
    • eof

      public T eof
      Returned by nextElement upon end of stream; we add to buffer also
    • lastMarker

      protected int lastMarker
      Track the last mark() call result value for use in rewind().
    • markDepth

      protected int markDepth
      tracks how deep mark() calls are nested
  • Constructor Details

    • LookaheadStream

      public LookaheadStream(T eof)
  • Method Details

    • reset

      public void reset()
      Overrides:
      reset in class FastQueue<T>
    • nextElement

      public abstract T nextElement()
      Implement nextElement to supply a stream of elements to this lookahead buffer. Return eof upon end of the stream we're pulling from.
    • remove

      public T remove()
      Get and remove first element in queue; override FastQueue.remove()
      Overrides:
      remove in class FastQueue<T>
    • consume

      public void consume()
      Make sure we have at least one element to remove, even if EOF
    • sync

      public void sync(int need)
      Make sure we have 'need' elements from current position p. Last valid p index is data.size()-1. p+need-1 is the data index 'need' elements ahead. If we need 1 element, (p+1-1)==p must be < data.size().
    • fill

      public void fill(int n)
      add n elements to buffer
    • size

      public int size()
      Size of entire stream is unknown; we only know buffer size from FastQueue
      Overrides:
      size in class FastQueue<T>
    • LT

      public Object LT(int k)
    • LB

      protected Object LB(int k)
      Look backwards k nodes
    • getCurrentSymbol

      public Object getCurrentSymbol()
    • index

      public int index()
    • mark

      public int mark()
    • release

      public void release(int marker)
    • rewind

      public void rewind(int marker)
    • rewind

      public void rewind()
    • seek

      public void seek(int index)
      Seek to a 0-indexed position within data buffer. Can't handle case where you seek beyond end of existing buffer. Normally used to seek backwards in the buffer. Does not force loading of nodes.