|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.antlr.runtime.ANTLRStringStream
public class ANTLRStringStream
A pretty quick CharStream that pulls all data from an array directly. Every method call counts in the lexer. Java's strings aren't very good so I'm avoiding.
| Field Summary | |
|---|---|
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 |
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 |
| Fields inherited from interface org.antlr.runtime.CharStream |
|---|
EOF |
| Constructor Summary | |
|---|---|
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 |
|
| Method Summary | |
|---|---|
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()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected char[] data
protected int n
protected int p
protected int line
protected int charPositionInLine
protected int markDepth
protected List markers
protected int lastMarker
public String name
| Constructor Detail |
|---|
public ANTLRStringStream()
public ANTLRStringStream(String input)
public ANTLRStringStream(char[] data,
int numberOfActualCharsInArray)
| Method Detail |
|---|
public void reset()
public void consume()
consume in interface IntStreampublic int LA(int i)
IntStream
LA in interface IntStreampublic int LT(int i)
CharStream
LT in interface CharStreampublic int index()
index in interface IntStreampublic int size()
IntStream
size in interface IntStreampublic int mark()
IntStream
mark in interface IntStreampublic void rewind(int m)
IntStream
rewind in interface IntStreampublic void rewind()
IntStream
rewind in interface IntStreampublic void release(int marker)
IntStream
release in interface IntStreampublic void seek(int index)
seek in interface IntStream
public String substring(int start,
int stop)
CharStream
substring in interface CharStreampublic int getLine()
CharStream
getLine in interface CharStreampublic int getCharPositionInLine()
CharStream
getCharPositionInLine in interface CharStreampublic void setLine(int line)
CharStream
setLine in interface CharStreampublic void setCharPositionInLine(int pos)
setCharPositionInLine in interface CharStreampublic String getSourceName()
IntStream
getSourceName in interface IntStreampublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||