Interface IdlTokenizer
Iterates over a Smithy IDL model as a series of tokens.
-
Method Summary
Modifier and TypeMethodDescriptionstatic IdlTokenizer
create
(CharSequence model) Create a tokenizer for the given model.static IdlTokenizer
create
(String filename, CharSequence model) Create a tokenizer for the given filename and model.default void
Assert that the current token istoken
.default IdlToken
Assert that the current token is one oftokens
.int
Get the current column number of the tokenizer, starting at 1.Get the currentIdlToken
.int
Get the column of the current token.int
Get the end position of the curren token.If the current token is an error, get the error message associated with the token.default CharSequence
Get the lexeme of the current token.int
Get the line of the current token.default SourceLocation
Get the source location of the current token.If the current token is a number, get the associated parsed number.default int
Get the length of the current token.int
Get the start position of the current token.If the current token is a string or text block, get the parsed content as a CharSequence.int
getLine()
Get the current line number of the tokenizer, starting at 1.getModel()
Get the model being tokenized.default CharSequence
getModel
(int start, int end) Get a borrowed slice of the model being tokenized.int
Get the current position of the tokenizer.Get the filename of the content being tokenized.default boolean
isCurrentLexeme
(CharSequence chars) Test if the current token lexeme is equal to the givechars
.Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
create
Create a tokenizer for the given model.- Parameters:
model
- IDL model contents to parse.- Returns:
- Returns the tokenizer.
-
create
Create a tokenizer for the given filename and model.- Parameters:
filename
- Filename being parsed.model
- IDL model contents to parse.- Returns:
- Returns the tokenizer.
-
getSourceFilename
String getSourceFilename()Get the filename of the content being tokenized.- Returns:
- Returns the filename used in source locations.
-
getModel
CharSequence getModel()Get the model being tokenized.- Returns:
- Returns the model.
-
getModel
Get a borrowed slice of the model being tokenized.- Parameters:
start
- Start position to get, inclusive.end
- End position to stop at, exclusive.- Returns:
- Returns the slice.
-
getPosition
int getPosition()Get the current position of the tokenizer.- Returns:
- Returns the absolute position.
-
getLine
int getLine()Get the current line number of the tokenizer, starting at 1.- Returns:
- Get the current line number.
-
getColumn
int getColumn()Get the current column number of the tokenizer, starting at 1.- Returns:
- Get the current column number.
-
getCurrentToken
IdlToken getCurrentToken()Get the currentIdlToken
.- Returns:
- Return the current token type.
-
getCurrentTokenLine
int getCurrentTokenLine()Get the line of the current token.- Returns:
- Return the line of the current token.
-
getCurrentTokenColumn
int getCurrentTokenColumn()Get the column of the current token.- Returns:
- Return the column of the current token.
-
getCurrentTokenStart
int getCurrentTokenStart()Get the start position of the current token.- Returns:
- Return the 0-based start position of the current token.
-
getCurrentTokenEnd
int getCurrentTokenEnd()Get the end position of the curren token.- Returns:
- Return the 0-based end position of the current token.
-
getCurrentTokenSpan
default int getCurrentTokenSpan()Get the length of the current token.- Returns:
- Return the current token span.
-
getCurrentTokenLocation
Get the source location of the current token.- Returns:
- Return the current token source location.
-
getCurrentTokenLexeme
Get the lexeme of the current token.- Returns:
- Returns the lexeme of the current token.
-
getCurrentTokenStringSlice
CharSequence getCurrentTokenStringSlice()If the current token is a string or text block, get the parsed content as a CharSequence. If the current token is an identifier, the lexeme of the identifier is returned.- Returns:
- Returns the parsed string content associated with the current token.
- Throws:
ModelSyntaxException
- if the current token is not a string, text block, or identifier.
-
getCurrentTokenNumberValue
Number getCurrentTokenNumberValue()If the current token is a number, get the associated parsed number.- Returns:
- Returns the parsed number associated with the current token.
- Throws:
ModelSyntaxException
- if the current token is not a number.
-
getCurrentTokenError
String getCurrentTokenError()If the current token is an error, get the error message associated with the token.- Returns:
- Returns the associated error message.
- Throws:
ModelSyntaxException
- if the current token is not an error.
-
expect
Assert that the current token istoken
.The tokenizer is not advanced after validating the current token.
- Parameters:
token
- Token to expect.- Throws:
ModelSyntaxException
- if the current token is unexpected.
-
expect
Assert that the current token is one oftokens
.The tokenizer is not advanced after validating the current token.
- Parameters:
tokens
- Assert that the current token is one of these tokens.- Returns:
- Returns the current token.
- Throws:
ModelSyntaxException
- if the current token is unexpected.
-
isCurrentLexeme
Test if the current token lexeme is equal to the givechars
.- Parameters:
chars
- Characters to compare the current lexeme against.- Returns:
- Returns true if the current lexeme is equal to
chars
.
-