-
- All Known Implementing Classes:
LookAheadBuffer
public interface ILookAheadBufferPrediction buffer that holds a certain number of tokens. Tokens are consumed when the are matched, and the buffer is kept filled all the time until end of token stream is reached.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanallConsumed()voidconsume()Consumes the first element of the buffer.voidinit()intlength()IParserTokenlookAhead(int depth)Looks ahead by a depth amount.booleanmatch(String type)Matches a given type to the token type found at the first element of the buffer.intmaxDepth()voidsetLookAheadDepth(int depth)Depth of the lookahead can be changed after creation.
-
-
-
Method Detail
-
match
boolean match(String type)
Matches a given type to the token type found at the first element of the buffer.- Parameters:
type- to match against first element in buffer- Returns:
- true if match is successful
-
consume
void consume() throws IOException, ScannerExceptionConsumes the first element of the buffer.- Throws:
ScannerExceptionIOException
-
allConsumed
boolean allConsumed()
- Returns:
- true if all tokens from both the input stream and the lookahead buffer have been consumed
-
lookAhead
IParserToken lookAhead(int depth) throws IOException, ScannerException, IndexOutOfBoundsException
Looks ahead by a depth amount. The lowest depth to look ahead is 1. Note that in some cases, a lookahead may be attempted on an earlier error condition that lead to an empty buffer (e.g., an exception was thrown during a fill process, and although more tokens may remain in the input source, the lookahead value may itself be null. Consequently, the lookahead buffer refills first before attempting the lookahead.- Parameters:
depth- to lookahead- Returns:
- token at specified lookahead depth or
IndexOutOfBoundsException. - Throws:
ScannerExceptionIOExceptionIndexOutOfBoundsException- if depth is outside the depth range of the buffer. Minimum depth is always 1.
-
length
int length()
-
maxDepth
int maxDepth()
-
init
void init() throws IOException, ScannerException
- Throws:
ScannerExceptionIOException
-
setLookAheadDepth
void setLookAheadDepth(int depth) throws IOException, ScannerExceptionDepth of the lookahead can be changed after creation.
If the new depth is less that the current depth, no new tokens will be read until the outstanding tokens (current depth - new depth) are first consumed.
If the new depth is greater than the current depth, the lookahead will read new tokens to fill the delta.- Parameters:
depth- to change- Throws:
ScannerException- as increasing the current depth of the buffer requires to fill the buffer to the new lengthIOException
-
-