Class Tokens
java.lang.Object
org.infosmid.stream.dsl.Tokens
-
Method Summary
Modifier and TypeMethodDescriptionprotected voidIndicate that the current token has been successfully processed.intDecrement the current token position and return the new position.protected Tokeneat()Consume the next token.Consume the next token if it matches the indicated token kind; otherwise throwCheckPointedParseException.Return the expression string converted to tokens.intReturn an immutable list oftokensbooleanhasNext()Returntrueif there are more tokens to process.booleanReturntrueif the first character of the token at the current position is the same as the last character of the token at the previous position.protected booleanReturntrueif the token in the position indicated byposition+distancematches the token indicated bydesiredTokenKind.next()Return the nextTokenand advance the current token position.peek()Return the token at the current position.protected Tokenpeek(int howFarAhead) Return the token at a specified distance beyond current position.booleanReturntrueif the indicated token matches the current token position.intposition()Return the current token position.voidraiseException(int position, DSLMessage message, Object... inserts) Throw a newCheckPointedParseExceptionbased on the current and last successfully processed token position.
-
Method Details
-
getExpression
Return the expression string converted to tokens.- Returns:
- expression string
-
decrementPosition
public int decrementPosition()Decrement the current token position and return the new position.- Returns:
- new token position
-
position
public int position()Return the current token position.- Returns:
- current token position
-
getTokenStream
-
lookAhead
Returntrueif the token in the position indicated byposition+distancematches the token indicated bydesiredTokenKind.- Parameters:
distance- number of token positions past the current positiondesiredTokenKind- the token to check for- Returns:
- true if the token at the indicated position matches
desiredTokenKind
-
hasNext
public boolean hasNext()Returntrueif there are more tokens to process.- Returns:
trueif there are more tokens to process
-
peek
Return the token at the current position. If there are no more tokens, returnnull.- Returns:
- token at current position or
nullif there are no more tokens
-
peek
Return the token at a specified distance beyond current position. If that is off the end of the list of known tokens, returnnull.- Parameters:
howFarAhead- how many character positions to peek ahead.- Returns:
- token at specified distance beyond current position or
nullif there are no more tokens
-
peek
Returntrueif the indicated token matches the current token position.- Parameters:
desiredTokenKind- token to match- Returns:
- true if the current token kind matches the provided token kind
-
next
-
eat
Consume the next token if it matches the indicated token kind; otherwise throwCheckPointedParseException.- Parameters:
expectedKind- the expected token kind- Returns:
- the next token
- Throws:
CheckPointedParseException- if the next token does not match the expected token kind
-
eat
Consume the next token. ThrowCheckPointedParseExceptionif there is nothing to consume.- Returns:
- the next token
- Throws:
CheckPointedParseException- if there are no more tokens
-
isNextAdjacent
public boolean isNextAdjacent()Returntrueif the first character of the token at the current position is the same as the last character of the token at the previous position.- Returns:
- true if the first character of the current token matches the last character of the previous token
-
checkpoint
protected void checkpoint()Indicate that the current token has been successfully processed.- See Also:
-
raiseException
Throw a newCheckPointedParseExceptionbased on the current and last successfully processed token position.- Parameters:
position- position where parse error occurredmessage- parse exception messageinserts- variables that may be inserted in the error message
-
getLine
- Parameters:
token- the token for which to determine the line- Returns:
- which line the token is on, starting from 0
-