Package antlr
Class InputBuffer
- java.lang.Object
-
- antlr.InputBuffer
-
- Direct Known Subclasses:
ByteBuffer,CharBuffer,DebuggingInputBuffer
public abstract class InputBuffer extends java.lang.ObjectA Stream of characters fed to the lexer from a InputStream that can be rewound via mark()/rewind() methods.A dynamic array is used to buffer up all the input characters. Normally, "k" characters are stored in the buffer. More characters may be stored during guess mode (testing syntactic predicate), or when LT(i>k) is referenced. Consumption of characters is deferred. In other words, reading the next character is not done by conume(), but deferred until needed by LA or LT.
- See Also:
CharQueue
-
-
Field Summary
Fields Modifier and Type Field Description protected intmarkerOffsetprotected intnMarkersprotected intnumToConsumeprotected CharQueuequeue
-
Constructor Summary
Constructors Constructor Description InputBuffer()Create an input buffer
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcommit()This method updates the state of the input buffer so that the text matched since the most recent mark() is no longer held by the buffer.voidconsume()Mark another character for deferred consumptionabstract voidfill(int amount)Ensure that the input buffer is sufficiently fulljava.lang.StringgetLAChars()java.lang.StringgetMarkedChars()booleanisMarked()charLA(int i)Get a lookahead characterintmark()Return an integer marker that can be used to rewind the buffer to its current state.voidreset()Reset the input buffervoidrewind(int mark)Rewind the character buffer to a marker.protected voidsyncConsume()Sync up deferred consumption
-
-
-
Field Detail
-
nMarkers
protected int nMarkers
-
markerOffset
protected int markerOffset
-
numToConsume
protected int numToConsume
-
queue
protected CharQueue queue
-
-
Method Detail
-
commit
public void commit()
This method updates the state of the input buffer so that the text matched since the most recent mark() is no longer held by the buffer. So, you either do a mark/rewind for failed predicate or mark/commit to keep on parsing without rewinding the input.
-
consume
public void consume()
Mark another character for deferred consumption
-
fill
public abstract void fill(int amount) throws CharStreamExceptionEnsure that the input buffer is sufficiently full- Throws:
CharStreamException
-
getLAChars
public java.lang.String getLAChars()
-
getMarkedChars
public java.lang.String getMarkedChars()
-
isMarked
public boolean isMarked()
-
LA
public char LA(int i) throws CharStreamExceptionGet a lookahead character- Throws:
CharStreamException
-
mark
public int mark()
Return an integer marker that can be used to rewind the buffer to its current state.
-
rewind
public void rewind(int mark)
Rewind the character buffer to a marker.- Parameters:
mark- Marker returned previously from mark()
-
reset
public void reset()
Reset the input buffer
-
syncConsume
protected void syncConsume()
Sync up deferred consumption
-
-