antlr

Class InputBuffer

Known Direct Subclasses:
ByteBuffer, CharBuffer, DebuggingInputBuffer

public abstract class InputBuffer
extends Object

A 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

protected int
markerOffset
protected int
nMarkers
protected int
numToConsume
protected CharQueue
queue

Constructor Summary

InputBuffer()
Create an input buffer

Method Summary

char
LA(int i)
Get a lookahead character
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.
void
consume()
Mark another character for deferred consumption
abstract void
fill(int amount)
Ensure that the input buffer is sufficiently full
String
getLAChars()
String
getMarkedChars()
boolean
isMarked()
int
mark()
Return an integer marker that can be used to rewind the buffer to its current state.
void
reset()
Reset the input buffer
void
rewind(int mark)
Rewind the character buffer to a marker.
protected void
syncConsume()
Sync up deferred consumption

Field Details

markerOffset

protected int markerOffset

nMarkers

protected int nMarkers

numToConsume

protected int numToConsume

queue

protected CharQueue queue

Constructor Details

InputBuffer

public InputBuffer()
Create an input buffer

Method Details

LA

public char LA(int i)
            throws CharStreamException
Get a lookahead character

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 CharStreamException
Ensure that the input buffer is sufficiently full

getLAChars

public String getLAChars()

getMarkedChars

public String getMarkedChars()

isMarked

public boolean isMarked()

mark

public int mark()
Return an integer marker that can be used to rewind the buffer to its current state.

reset

public void reset()
Reset the input buffer

rewind

public void rewind(int mark)
Rewind the character buffer to a marker.
Parameters:
mark - Marker returned previously from mark()

syncConsume

protected void syncConsume()
Sync up deferred consumption