public class ANTLRInputStream extends Object implements CharStream
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.
Modifier and Type | Field and Description |
---|---|
protected char[] |
data
The data being scanned
|
static int |
INITIAL_BUFFER_SIZE |
protected int |
n
How many characters are actually in the buffer
|
String |
name
What is name or source of this char stream?
|
protected int |
p
0..n-1 index into string of next char
|
static int |
READ_BUFFER_SIZE |
EOF, UNKNOWN_SOURCE_NAME
Constructor and Description |
---|
ANTLRInputStream() |
ANTLRInputStream(char[] data,
int numberOfActualCharsInArray)
This is the preferred constructor for strings as no data is copied
|
ANTLRInputStream(InputStream input) |
ANTLRInputStream(InputStream input,
int initialSize) |
ANTLRInputStream(InputStream input,
int initialSize,
int readChunkSize) |
ANTLRInputStream(Reader r) |
ANTLRInputStream(Reader r,
int initialSize) |
ANTLRInputStream(Reader r,
int initialSize,
int readChunkSize) |
ANTLRInputStream(String input)
Copy data in string to a local char array
|
Modifier and Type | Method and Description |
---|---|
void |
consume()
Consumes the current symbol in the stream.
|
String |
getSourceName()
Gets the name of the underlying symbol source.
|
String |
getText(Interval interval)
This method returns the text for a range of characters within this input
stream.
|
int |
index()
Return the current input symbol index 0..n where n indicates the
last symbol has been read.
|
int |
LA(int i)
Gets the value of the symbol at offset
i from the current
position. |
void |
load(Reader r,
int size,
int readChunkSize) |
int |
LT(int i) |
int |
mark()
mark/release do nothing; we have entire buffer
|
void |
release(int marker)
This method releases a marked range created by a call to
mark() . |
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.
|
void |
seek(int index)
consume() ahead until p==index; can't just set p=index as we must
update line and charPositionInLine.
|
int |
size()
Returns the total number of symbols in the stream, including a single EOF
symbol.
|
String |
toString() |
public static final int READ_BUFFER_SIZE
public static final int INITIAL_BUFFER_SIZE
protected char[] data
protected int n
protected int p
public String name
public ANTLRInputStream()
public ANTLRInputStream(String input)
public ANTLRInputStream(char[] data, int numberOfActualCharsInArray)
public ANTLRInputStream(Reader r) throws IOException
IOException
public ANTLRInputStream(Reader r, int initialSize) throws IOException
IOException
public ANTLRInputStream(Reader r, int initialSize, int readChunkSize) throws IOException
IOException
public ANTLRInputStream(InputStream input) throws IOException
IOException
public ANTLRInputStream(InputStream input, int initialSize) throws IOException
IOException
public ANTLRInputStream(InputStream input, int initialSize, int readChunkSize) throws IOException
IOException
public void load(Reader r, int size, int readChunkSize) throws IOException
IOException
public void reset()
public void consume()
IntStream
index()
before calling this method is less than the value of index()
after calling this method.LA(1)
before
calling this method becomes the value of LA(-1)
after calling
this method.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).public int LA(int i)
IntStream
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.
public int LT(int i)
public int index()
public int size()
IntStream
public int mark()
public void release(int marker)
IntStream
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()
.
release
in interface IntStream
marker
- A marker returned by a call to mark()
.IntStream.mark()
public void seek(int index)
public String getText(Interval interval)
CharStream
interval
lies entirely within a marked range. For more
information about marked ranges, see IntStream.mark()
.getText
in interface CharStream
interval
- an interval within the streampublic String getSourceName()
IntStream
IntStream.UNKNOWN_SOURCE_NAME
.getSourceName
in interface IntStream
Copyright © 1992–2014 ANTLR. All rights reserved.