public class ANTLRStringStream extends Object implements CharStream
Modifier and Type | Field and Description |
---|---|
protected int |
charPositionInLine
The index of the character relative to the beginning of the line 0..n-1
|
protected char[] |
data
The data being scanned
|
protected int |
lastMarker
Track the last mark() call result value for use in rewind().
|
protected int |
line
line number 1..n within the input
|
protected int |
markDepth
tracks how deep mark() calls are nested
|
protected List<CharStreamState> |
markers
A list of CharStreamState objects that tracks the stream state
values line, charPositionInLine, and p that can change as you
move through the input stream.
|
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
|
EOF
Constructor and Description |
---|
ANTLRStringStream() |
ANTLRStringStream(char[] data,
int numberOfActualCharsInArray)
This is the preferred constructor as no data is copied
|
ANTLRStringStream(String input)
Copy data in string to a local char array
|
Modifier and Type | Method and Description |
---|---|
void |
consume() |
int |
getCharPositionInLine()
The index of the character relative to the beginning of the line 0..n-1
|
int |
getLine()
ANTLR tracks the line information automatically
|
String |
getSourceName()
Where are you getting symbols from? Normally, implementations will
pass the buck all the way to the lexer who can ask its input stream
for the file name or whatever.
|
int |
index()
Return the current input symbol index 0..n where n indicates the
last symbol has been read.
|
int |
LA(int i)
Get int at current input pointer + i ahead where i=1 is next int.
|
int |
LT(int i)
Get the ith character of lookahead.
|
int |
mark()
Tell the stream to start buffering if it hasn't already.
|
void |
release(int marker)
You may want to commit to a backtrack but don't want to force the
stream to keep bookkeeping objects around for a marker that is
no longer necessary.
|
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 |
rewind()
Rewind to the input position of the last marker.
|
void |
rewind(int m)
Reset the stream so that next call to index would return marker.
|
void |
seek(int index)
consume() ahead until p==index; can't just set p=index as we must
update line and charPositionInLine.
|
void |
setCharPositionInLine(int pos) |
void |
setLine(int line)
Because this stream can rewind, we need to be able to reset the line
|
int |
size()
Only makes sense for streams that buffer everything up probably, but
might be useful to display the entire stream or for testing.
|
String |
substring(int start,
int stop)
For infinite streams, you don't need this; primarily I'm providing
a useful interface for action code.
|
String |
toString() |
protected char[] data
protected int n
protected int p
protected int line
protected int charPositionInLine
protected int markDepth
protected List<CharStreamState> markers
protected int lastMarker
public String name
public ANTLRStringStream()
public ANTLRStringStream(String input)
public ANTLRStringStream(char[] data, int numberOfActualCharsInArray)
public void reset()
public int LA(int i)
IntStream
public int LT(int i)
CharStream
LT
in interface CharStream
public int index()
public int size()
IntStream
public int mark()
IntStream
public void rewind(int m)
IntStream
public void rewind()
IntStream
public void release(int marker)
IntStream
public void seek(int index)
public String substring(int start, int stop)
CharStream
substring
in interface CharStream
public int getLine()
CharStream
getLine
in interface CharStream
public int getCharPositionInLine()
CharStream
getCharPositionInLine
in interface CharStream
public void setLine(int line)
CharStream
setLine
in interface CharStream
public void setCharPositionInLine(int pos)
setCharPositionInLine
in interface CharStream
public String getSourceName()
IntStream
getSourceName
in interface IntStream
Copyright © 1992–2015 ANTLR. All rights reserved.