Top Description Fields Constructors Methods
org.antlr.v4.runtime

public Class ANTLRInputStream

extends Object
implements UnicodeCharStream, CharStream
Class Inheritance
All Implemented Interfaces
org.antlr.v4.runtime.CharStream, org.antlr.v4.runtime.IntStream, org.antlr.v4.runtime.UnicodeCharStream
Known Direct Subclasses
org.antlr.v4.runtime.ANTLRFileStream
Annotations
@Deprecated
Imports
org.antlr.v4.runtime.misc.Interval, java.io.IOException, .InputStream, .InputStreamReader, .Reader, java.util.Arrays

Deprecated

as of 4.7 Please use CharStreams interface.

Vacuum all input from a Reader/InputStream and then treat it like a char[] buffer. Can also pass in a String or char[] to use.

If you need encoding, pass in stream/reader with correct encoding.

Field Summary

Modifier and TypeField and Description
protected char[]
data

The data being scanned

public static final int
protected int
n

How many characters are actually in the buffer

public String
name

What is name or source of this char stream?

protected int
p

0..n-1 index into string of next char

public static final int

Constructor Summary

AccessConstructor and Description
public
public
ANTLRInputStream(String input)

Copy data in string to a local char array

public
ANTLRInputStream(char[] data, int numberOfActualCharsInArray)

This is the preferred constructor for strings as no data is copied

public
public
ANTLRInputStream(Reader r, int initialSize)

public
ANTLRInputStream(Reader r, int initialSize, int readChunkSize)

public
public
ANTLRInputStream(InputStream input, int initialSize)

public
ANTLRInputStream(InputStream input, int initialSize, int readChunkSize)

Method Summary

Modifier and TypeMethod and Description
public void
consume()

Implements org.antlr.v4.runtime.IntStream.consume.

Consumes the current symbol in the stream.
public String
getSourceName()

Implements org.antlr.v4.runtime.IntStream.getSourceName.

Gets the name of the underlying symbol source.
public String
getText(Interval
an interval within the stream
interval
)

Implements org.antlr.v4.runtime.CharStream.getText.

This method returns the text for a range of characters within this input stream.
public int
index()

Implements org.antlr.v4.runtime.IntStream.index.

Return the current input symbol index 0..n where n indicates the last symbol has been read.
public int
LA(int i)

Implements org.antlr.v4.runtime.IntStream.LA.

Gets the value of the symbol at offset i from the current position.
public void
load(Reader r, int size, int readChunkSize)

public int
LT(int i)

public int
mark()

Implements org.antlr.v4.runtime.IntStream.mark.

mark/release do nothing; we have entire buffer
public void
release(int
A marker returned by a call to mark().
marker
)

Implements org.antlr.v4.runtime.IntStream.release.

This method releases a marked range created by a call to mark().
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.

public void
seek(int
The absolute index to seek to.
index
)

Implements org.antlr.v4.runtime.IntStream.seek.

consume() ahead until p==index; can't just set p=index as we must update line and charPositionInLine.
public int
size()

Implements org.antlr.v4.runtime.IntStream.size.

Returns the total number of symbols in the stream, including a single EOF symbol.
public boolean
supportsUnicodeCodePoints()

Implements org.antlr.v4.runtime.UnicodeCharStream.supportsUnicodeCodePoints.

Determines if the current stream supports Unicode code points.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

databack to summary
protected char[] data

The data being scanned

INITIAL_BUFFER_SIZEback to summary
public static final int INITIAL_BUFFER_SIZE
nback to summary
protected int n

How many characters are actually in the buffer

nameback to summary
public String name

What is name or source of this char stream?

pback to summary
protected int p

0..n-1 index into string of next char

READ_BUFFER_SIZEback to summary
public static final int READ_BUFFER_SIZE

Constructor Detail

ANTLRInputStreamback to summary
public ANTLRInputStream()
ANTLRInputStreamback to summary
public ANTLRInputStream(String input)

Copy data in string to a local char array

ANTLRInputStreamback to summary
public ANTLRInputStream(char[] data, int numberOfActualCharsInArray)

This is the preferred constructor for strings as no data is copied

ANTLRInputStreamback to summary
public ANTLRInputStream(Reader r) throws IOException
ANTLRInputStreamback to summary
public ANTLRInputStream(Reader r, int initialSize) throws IOException
ANTLRInputStreamback to summary
public ANTLRInputStream(Reader r, int initialSize, int readChunkSize) throws IOException
ANTLRInputStreamback to summary
public ANTLRInputStream(InputStream input) throws IOException
ANTLRInputStreamback to summary
public ANTLRInputStream(InputStream input, int initialSize) throws IOException
ANTLRInputStreamback to summary
public ANTLRInputStream(InputStream input, int initialSize, int readChunkSize) throws IOException

Method Detail

consumeback to summary
public void consume()

Implements org.antlr.v4.runtime.IntStream.consume.

Doc from org.antlr.v4.runtime.IntStream.consume.

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).
Annotations
@Override
getSourceNameback to summary
public String getSourceName()

Implements org.antlr.v4.runtime.IntStream.getSourceName.

Doc from org.antlr.v4.runtime.IntStream.getSourceName.

Gets the name of the underlying symbol source. This method returns a non-null, non-empty string. If such a name is not known, this method returns UNKNOWN_SOURCE_NAME.

Annotations
@Override
getTextback to summary
public String getText(Interval interval)

Implements org.antlr.v4.runtime.CharStream.getText.

Doc from org.antlr.v4.runtime.CharStream.getText.

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.

Parameters
interval:Interval

an interval within the stream

Returns:String

the text of the specified interval

Annotations
@Override
indexback to summary
public int index()

Implements org.antlr.v4.runtime.IntStream.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).

Annotations
@Override
LAback to summary
public int LA(int i)

Implements org.antlr.v4.runtime.IntStream.LA.

Doc from org.antlr.v4.runtime.IntStream.LA.

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

Annotations
@Override
loadback to summary
public void load(Reader r, int size, int readChunkSize) throws IOException
LTback to summary
public int LT(int i)
markback to summary
public int mark()

Implements org.antlr.v4.runtime.IntStream.mark.

mark/release do nothing; we have entire buffer

Returns:int

Doc from org.antlr.v4.runtime.IntStream.mark.

An opaque marker which should be passed to release() when the marked range is no longer required.

Annotations
@Override
releaseback to summary
public void release(int marker)

Implements org.antlr.v4.runtime.IntStream.release.

Doc from org.antlr.v4.runtime.IntStream.release.

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

Parameters
marker:int

A marker returned by a call to mark().

Annotations
@Override
resetback to summary
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.

seekback to summary
public void seek(int index)

Implements org.antlr.v4.runtime.IntStream.seek.

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

Parameters
index:int

Doc from org.antlr.v4.runtime.IntStream.seek.

The absolute index to seek to.

Annotations
@Override
sizeback to summary
public int size()

Implements org.antlr.v4.runtime.IntStream.size.

Doc from org.antlr.v4.runtime.IntStream.size.

Returns the total number of symbols in the stream, including a single EOF symbol.

Annotations
@Override
supportsUnicodeCodePointsback to summary
public boolean supportsUnicodeCodePoints()

Implements org.antlr.v4.runtime.UnicodeCharStream.supportsUnicodeCodePoints.

Doc from org.antlr.v4.runtime.UnicodeCharStream.supportsUnicodeCodePoints.

Determines if the current stream supports Unicode code points.

Returns:boolean

true if the current input stream supports Unicode code points; otherwise, false if the current input stream returns UTF-16 code units for code points above U+FFFF.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override