Class ANTLRInputStream

    • Field Detail

      • data

        protected char[] data
        The data being scanned
      • n

        protected int n
        How many characters are actually in the buffer
      • p

        protected int p
        0..n-1 index into string of next char
      • name

        public String name
        What is name or source of this char stream?
    • Constructor Detail

      • ANTLRInputStream

        public ANTLRInputStream()
      • ANTLRInputStream

        public ANTLRInputStream​(String input)
        Copy data in string to a local char array
      • ANTLRInputStream

        public ANTLRInputStream​(char[] data,
                                int numberOfActualCharsInArray)
        This is the preferred constructor for strings as no data is copied
    • Method Detail

      • reset

        public void reset()
        Reset the stream so that it's in the same state it was when the object was created *except* the data array is not touched.
      • consume

        public void consume()
        Description copied from interface: IntStream
        Consumes the current symbol in the stream. This method has the following effects:
        • Forward movement: The value of index() before calling this method is less than the value of index() after calling this method.
        • Ordered lookahead: The value of LA(1) before calling this method becomes the value of LA(-1) after calling this method.
        Note that calling this method does not guarantee that index() is incremented by exactly 1, as that would preclude the ability to implement filtering streams (e.g. CommonTokenStream which distinguishes between "on-channel" and "off-channel" tokens).
        Specified by:
        consume in interface IntStream
      • LA

        public int LA​(int i)
        Description copied from interface: IntStream
        Gets the value of the symbol at offset i from the current position. When i==1, this method returns the value of the current symbol in the stream (which is the next symbol to be consumed). When i==-1, this method returns the value of the previously read symbol in the stream. It is not valid to call this method with i==0, but the specific behavior is unspecified because this method is frequently called from performance-critical code.

        This method is guaranteed to succeed if any of the following are true:

        • i>0
        • i==-1 and index() returns a value greater than the value of index() after the stream was constructed and LA(1) was called in that order. Specifying the current index() relative to the index after the stream was created allows for filtering implementations that do not return every symbol from the underlying source. Specifying the call to LA(1) allows for lazily initialized streams.
        • LA(i) refers to a symbol consumed within a marked region that has not yet been released.

        If i represents a position at or beyond the end of the stream, this method returns IntStream.EOF.

        The return value is unspecified if i<0 and fewer than -i calls to consume() have occurred from the beginning of the stream before calling this method.

        Specified by:
        LA in interface IntStream
      • LT

        public int LT​(int i)
      • index

        public int index()
        Return the current input symbol index 0..n where n indicates the last symbol has been read. The index is the index of char to be returned from LA(1).
        Specified by:
        index in interface IntStream
      • size

        public int size()
        Description copied from interface: IntStream
        Returns the total number of symbols in the stream, including a single EOF symbol.
        Specified by:
        size in interface IntStream
      • mark

        public int mark()
        mark/release do nothing; we have entire buffer
        Specified by:
        mark in interface IntStream
        Returns:
        An opaque marker which should be passed to release() when the marked range is no longer required.
      • release

        public void release​(int marker)
        Description copied from interface: IntStream
        This method releases a marked range created by a call to mark(). Calls to release() must appear in the reverse order of the corresponding calls to mark(). If a mark is released twice, or if marks are not released in reverse order of the corresponding calls to mark(), the behavior is unspecified.

        For more information and an example, see IntStream.mark().

        Specified by:
        release in interface IntStream
        Parameters:
        marker - A marker returned by a call to mark().
        See Also:
        IntStream.mark()
      • seek

        public void seek​(int index)
        consume() ahead until p==index; can't just set p=index as we must update line and charPositionInLine. If we seek backwards, just set p
        Specified by:
        seek in interface IntStream
        Parameters:
        index - The absolute index to seek to.
      • getText

        public String getText​(Interval interval)
        Description copied from interface: CharStream
        This method returns the text for a range of characters within this input stream. This method is guaranteed to not throw an exception if the specified interval lies entirely within a marked range. For more information about marked ranges, see IntStream.mark().
        Specified by:
        getText in interface CharStream
        Parameters:
        interval - an interval within the stream
        Returns:
        the text of the specified interval