类 ANTLRStringStream
- java.lang.Object
-
- org.antlr.runtime.ANTLRStringStream
-
- 所有已实现的接口:
CharStream,IntStream
- 直接已知子类:
ANTLRFileStream,ANTLRReaderStream
public class ANTLRStringStream extends java.lang.Object implements CharStream
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.
-
-
字段概要
字段 修饰符和类型 字段 说明 protected intcharPositionInLineThe index of the character relative to the beginning of the line 0..n-1protected char[]dataThe data being scannedprotected intlastMarkerTrack the last mark() call result value for use in rewind().protected intlineline number 1..n within the inputprotected intmarkDepthtracks how deep mark() calls are nestedprotected java.util.List<CharStreamState>markersA 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 intnHow many characters are actually in the bufferjava.lang.StringnameWhat is name or source of this char stream?protected intp0..n-1 index into string of next char-
从接口继承的字段 org.antlr.runtime.CharStream
EOF
-
-
构造器概要
构造器 构造器 说明 ANTLRStringStream()ANTLRStringStream(char[] data, int numberOfActualCharsInArray)This is the preferred constructor as no data is copiedANTLRStringStream(java.lang.String input)Copy data in string to a local char array
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidconsume()intgetCharPositionInLine()The index of the character relative to the beginning of the line 0..n-1intgetLine()ANTLR tracks the line information automaticallyjava.lang.StringgetSourceName()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.intindex()Return the current input symbol index 0..n where n indicates the last symbol has been read.intLA(int i)Get int at current input pointer + i ahead where i=1 is next int.intLT(int i)Get the ith character of lookahead.intmark()Tell the stream to start buffering if it hasn't already.voidrelease(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.voidreset()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.voidrewind()Rewind to the input position of the last marker.voidrewind(int m)Reset the stream so that next call to index would return marker.voidseek(int index)consume() ahead until p==index; can't just set p=index as we must update line and charPositionInLine.voidsetCharPositionInLine(int pos)voidsetLine(int line)Because this stream can rewind, we need to be able to reset the lineintsize()Only makes sense for streams that buffer everything up probably, but might be useful to display the entire stream or for testing.java.lang.Stringsubstring(int start, int stop)For infinite streams, you don't need this; primarily I'm providing a useful interface for action code.java.lang.StringtoString()
-
-
-
字段详细资料
-
data
protected char[] data
The data being scanned
-
n
protected int n
How many characters are actually in the buffer
-
p
protected int p
0..n-1 index into string of next char
-
line
protected int line
line number 1..n within the input
-
charPositionInLine
protected int charPositionInLine
The index of the character relative to the beginning of the line 0..n-1
-
markDepth
protected int markDepth
tracks how deep mark() calls are nested
-
markers
protected java.util.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. Indexed from 1..markDepth. A null is kept @ index 0. Create upon first call to mark().
-
lastMarker
protected int lastMarker
Track the last mark() call result value for use in rewind().
-
name
public java.lang.String name
What is name or source of this char stream?
-
-
构造器详细资料
-
ANTLRStringStream
public ANTLRStringStream()
-
ANTLRStringStream
public ANTLRStringStream(java.lang.String input)
Copy data in string to a local char array
-
ANTLRStringStream
public ANTLRStringStream(char[] data, int numberOfActualCharsInArray)This is the preferred constructor as no data is copied
-
-
方法详细资料
-
reset
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.
-
LA
public int LA(int i)
从接口复制的说明:IntStreamGet int at current input pointer + i ahead where i=1 is next int. Negative indexes are allowed. LA(-1) is previous token (token just matched). LA(-i) where i is before first token should yield -1, invalid char / EOF.
-
LT
public int LT(int i)
从接口复制的说明:CharStreamGet the ith character of lookahead. This is the same usually as LA(i). This will be used for labels in the generated lexer code. I'd prefer to return a char here type-wise, but it's probably better to be 32-bit clean and be consistent with LA.- 指定者:
LT在接口中CharStream
-
index
public int 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).
-
size
public int size()
从接口复制的说明:IntStreamOnly makes sense for streams that buffer everything up probably, but might be useful to display the entire stream or for testing. This value includes a single EOF.
-
mark
public int mark()
从接口复制的说明:IntStreamTell the stream to start buffering if it hasn't already. Return current input position, index(), or some other marker so that when passed to rewind() you get back to the same spot. rewind(mark()) should not affect the input cursor. The Lexer track line/col info as well as input index so its markers are not pure input indexes. Same for tree node streams.
-
rewind
public void rewind(int m)
从接口复制的说明:IntStreamReset the stream so that next call to index would return marker. The marker will usually be index() but it doesn't have to be. It's just a marker to indicate what state the stream was in. This is essentially calling release() and seek(). If there are markers created after this marker argument, this routine must unroll them like a stack. Assume the state the stream was in when this marker was created.
-
rewind
public void rewind()
从接口复制的说明:IntStreamRewind to the input position of the last marker. Used currently only after a cyclic DFA and just before starting a sem/syn predicate to get the input position back to the start of the decision. Do not "pop" the marker off the state. mark(i) and rewind(i) should balance still. It is like invoking rewind(last marker) but it should not "pop" the marker off. It's like seek(last marker's input position).
-
release
public void release(int marker)
从接口复制的说明:IntStreamYou 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. This will have the same behavior as rewind() except it releases resources without the backward seek. This must throw away resources for all markers back to the marker argument. So if you're nested 5 levels of mark(), and then release(2) you have to release resources for depths 2..5.
-
seek
public void seek(int index)
consume() ahead until p==index; can't just set p=index as we must update line and charPositionInLine.
-
substring
public java.lang.String substring(int start, int stop)从接口复制的说明:CharStreamFor infinite streams, you don't need this; primarily I'm providing a useful interface for action code. Just make sure actions don't use this on streams that don't support it.- 指定者:
substring在接口中CharStream
-
getLine
public int getLine()
从接口复制的说明:CharStreamANTLR tracks the line information automatically- 指定者:
getLine在接口中CharStream
-
getCharPositionInLine
public int getCharPositionInLine()
从接口复制的说明:CharStreamThe index of the character relative to the beginning of the line 0..n-1- 指定者:
getCharPositionInLine在接口中CharStream
-
setLine
public void setLine(int line)
从接口复制的说明:CharStreamBecause this stream can rewind, we need to be able to reset the line- 指定者:
setLine在接口中CharStream
-
setCharPositionInLine
public void setCharPositionInLine(int pos)
- 指定者:
setCharPositionInLine在接口中CharStream
-
getSourceName
public java.lang.String getSourceName()
从接口复制的说明:IntStreamWhere 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.- 指定者:
getSourceName在接口中IntStream
-
toString
public java.lang.String toString()
- 覆盖:
toString在类中java.lang.Object
-
-