public class Tokens
extends java.lang.Object
tokens
.
Furthermore, this class provides methods to process the tokens and
keeps track of the current token being processed.Constructor and Description |
---|
Tokens(java.lang.String expression)
Construct a
Tokens object based on the provided string expression. |
Modifier and Type | Method and Description |
---|---|
protected void |
checkpoint()
Indicate that a piece of the DSL has been successfully processed.
|
protected int |
decrementPosition()
Decrement the current token position and return the new position.
|
protected Token |
eat(TokenKind expectedKind)
Consume the next token if it matches the indicated token kind;
otherwise throw
CheckpointedJobDefinitionException . |
protected java.lang.String |
getExpression()
Return the expression string converted to tokens.
|
java.util.List<Token> |
getTokenStream()
Return an immutable list of
tokens |
protected boolean |
hasNext()
Return
true if there are more tokens to process. |
protected boolean |
isNextAdjacent()
Return
true if 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 boolean |
lookAhead(int distance,
TokenKind desiredTokenKind)
Return
true if the token in the position indicated
by position + distance matches
the token indicated by desiredTokenKind . |
protected boolean |
maybeEat(TokenKind desiredKind)
Consume the next token if it matches the desired token kind and return true; otherwise
return false.
|
protected Token |
next()
Return the next
Token and advance the current token position. |
protected Token |
peek()
Return the token at the current position.
|
protected Token |
peek(int offset)
Return the token at the specified offset from the current position.
|
protected boolean |
peek(int offset,
TokenKind tokenKind)
Peek at the token at an offset (relative to the current position) - if the token
matches the indicated kind, return true, otherwise return false.
|
protected boolean |
peek(TokenKind desiredTokenKind)
Return
true if the indicated token matches the current token
position. |
protected int |
position()
Return the current token position.
|
protected void |
raiseException(int position,
JobDSLMessage message,
java.lang.Object... inserts)
Throw a new
CheckpointedJobDefinitionException based on the current and
last successfully processed token position. |
java.lang.String |
toString() |
public Tokens(java.lang.String expression)
Tokens
object based on the provided string expression.expression
- string expression to convert into tokens
.protected java.lang.String getExpression()
protected int decrementPosition()
protected int position()
public java.util.List<Token> getTokenStream()
tokens
protected boolean lookAhead(int distance, TokenKind desiredTokenKind)
true
if the token in the position indicated
by position
+ distance
matches
the token indicated by desiredTokenKind
.distance
- number of token positions past the current positiondesiredTokenKind
- the token to check fordesiredTokenKind
protected boolean hasNext()
true
if there are more tokens to process.true
if there are more tokens to processprotected Token peek()
null
.null
if there are no more tokensprotected Token peek(int offset)
null
.null
if there are no more tokensprotected boolean peek(int offset, TokenKind tokenKind)
offset
- the offset from the current position to peek attokenKind
- the tokenKind to check againstprotected boolean peek(TokenKind desiredTokenKind)
true
if the indicated token matches the current token
position.desiredTokenKind
- token to matchprotected Token next()
Token
and advance the current token position.Token
protected Token eat(TokenKind expectedKind)
CheckpointedJobDefinitionException
.expectedKind
- the expected token kindCheckpointedJobDefinitionException
- if the next token does not match
the expected token kindprotected boolean maybeEat(TokenKind desiredKind)
desiredKind
- the desired token to eatprotected boolean isNextAdjacent()
true
if 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 void checkpoint()
lastGoodPosition
protected void raiseException(int position, JobDSLMessage message, java.lang.Object... inserts)
CheckpointedJobDefinitionException
based on the current and
last successfully processed token position.position
- position where parse error occurredmessage
- parse exception messageinserts
- variables that may be inserted in the error messagepublic java.lang.String toString()
toString
in class java.lang.Object