public class UnbufferedCharStream extends Object implements CharStream
Modifier and Type | Field and Description |
---|---|
protected int |
currentCharIndex
Absolute character index.
|
protected char[] |
data
A moving window buffer of the data being scanned.
|
protected Reader |
input |
protected int |
lastChar
This is the
LA(-1) character for the current position. |
protected int |
lastCharBufferStart
|
protected int |
n
The number of characters currently in
data . |
String |
name
The name or source of this char stream.
|
protected int |
numMarkers
|
protected int |
p
0..n-1 index into
data of next character. |
EOF, UNKNOWN_SOURCE_NAME
Constructor and Description |
---|
UnbufferedCharStream()
Useful for subclasses that pull char from other than this.input.
|
UnbufferedCharStream(InputStream input) |
UnbufferedCharStream(InputStream input,
int bufferSize) |
UnbufferedCharStream(int bufferSize)
Useful for subclasses that pull char from other than this.input.
|
UnbufferedCharStream(Reader input) |
UnbufferedCharStream(Reader input,
int bufferSize) |
Modifier and Type | Method and Description |
---|---|
protected void |
add(int c) |
void |
consume()
Consumes the current symbol in the stream.
|
protected int |
fill(int n)
Add
n characters to the buffer. |
protected int |
getBufferStartIndex() |
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 index into the stream of the input symbol referred to by
LA(1) . |
int |
LA(int i)
Gets the value of the symbol at offset
i from the current
position. |
int |
mark()
Return a marker that we can release later.
|
protected int |
nextChar()
Override to provide different source of characters than
input . |
void |
release(int marker)
Decrement number of markers, resetting buffer if we hit 0.
|
void |
seek(int index)
Seek to absolute character index, which might not be in the current
sliding window.
|
int |
size()
Returns the total number of symbols in the stream, including a single EOF
symbol.
|
protected void |
sync(int want)
Make sure we have 'need' elements from current position
p . |
protected char[] data
consume()
resets so
we start filling at index 0 again.protected int n
data
.
This is not the buffer capacity, that's data.length
.
protected int p
data
of next character.
The LA(1)
character is data[p]
. If p == n
, we are
out of buffered characters.
protected int numMarkers
protected int lastChar
LA(-1)
character for the current position.protected int lastCharBufferStart
numMarkers > 0
, this is the LA(-1)
character for the
first character in data
. Otherwise, this is unspecified.protected int currentCharIndex
LA(1)
. Goes from 0 to the number of characters in the
entire stream, although the stream size is unknown before the end is
reached.protected Reader input
public String name
public UnbufferedCharStream()
public UnbufferedCharStream(int bufferSize)
public UnbufferedCharStream(InputStream input)
public UnbufferedCharStream(Reader input)
public UnbufferedCharStream(InputStream input, int bufferSize)
public UnbufferedCharStream(Reader input, int bufferSize)
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).protected void sync(int want)
p
.
Last valid p
index is data.length-1
. p+need-1
is
the char index 'need' elements ahead. If we need 1 element,
(p+1-1)==p
must be less than data.length
.protected int fill(int n)
n
characters to the buffer. Returns the number of characters
actually added to the buffer. If the return value is less than n
,
then EOF was reached before n
characters could be added.protected int nextChar() throws IOException
input
.IOException
protected void add(int c)
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 mark()
The specific marker value used for this class allows for some level of
protection against misuse where seek()
is called on a mark or
release()
is called in the wrong order.
public void release(int marker)
release
in interface IntStream
marker
- IntStream.mark()
public int index()
IntStream
LA(1)
.
The behavior of this method is unspecified if no call to an
initializing method
has occurred after this stream was
constructed.
public void seek(int index)
p
to index-bufferStartIndex
.public int size()
IntStream
public String getSourceName()
IntStream
IntStream.UNKNOWN_SOURCE_NAME
.getSourceName
in interface IntStream
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 streamprotected final int getBufferStartIndex()
Copyright © 1992-2015 ANTLR. All Rights Reserved.