Package software.amazon.smithy.syntax
Class CapturedToken
java.lang.Object
software.amazon.smithy.syntax.CapturedToken
- All Implemented Interfaces:
FromSourceLocation
,ToSmithyBuilder<CapturedToken>
public final class CapturedToken
extends Object
implements FromSourceLocation, ToSmithyBuilder<CapturedToken>
A persisted token captured from an
IdlTokenizer
.
For performance, IdlTokenizer
does not create new tokens types for each encountered token. Instead, it
updates the current state of the tokenizer and allows the caller to inspect the tokenizer for information about each
token. Because smithy-syntax needs to create a token-tree rather than go directly to an AST, it requires arbitrary
lookahead of tokens, requiring it to persist tokens in memory.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CapturedToken.Builder
builder()
static CapturedToken
from
(IdlTokenizer tokenizer) Persist the current token of anIdlTokenizer
.static CapturedToken
from
(IdlTokenizer tokenizer, Function<CharSequence, String> stringTable) Persist the current token of anIdlTokenizer
.int
int
Gets the associated error message with the token if it's an error.Get the token IDL token of the captured token.Get the raw lexeme of the current token.Get the computedNumber
of the current token if it's a number.int
Gets the source location of a value.int
getSpan()
int
int
Get the associated String contents of the token if it's a string, text block, or identifier.Take this object and create a builder that contains all of the current property values of this object.
-
Method Details
-
builder
-
from
Persist the current token of anIdlTokenizer
.- Parameters:
tokenizer
- Tokenizer to capture.- Returns:
- Returns the persisted token.
-
from
Persist the current token of anIdlTokenizer
.- Parameters:
tokenizer
- Tokenizer to capture.stringTable
- String table that caches previously created strings.- Returns:
- Returns the persisted token.
-
toBuilder
Description copied from interface:ToSmithyBuilder
Take this object and create a builder that contains all of the current property values of this object.- Specified by:
toBuilder
in interfaceToSmithyBuilder<CapturedToken>
- Returns:
- a builder for type T
-
getIdlToken
Get the token IDL token of the captured token.- Returns:
- Returns the underlying token type.
-
getSourceLocation
Description copied from interface:FromSourceLocation
Gets the source location of a value.- Specified by:
getSourceLocation
in interfaceFromSourceLocation
- Returns:
- Returns the source location of the value.
-
getFilename
-
getPosition
public int getPosition() -
getStartLine
public int getStartLine() -
getStartColumn
public int getStartColumn() -
getEndLine
public int getEndLine() -
getEndColumn
public int getEndColumn() -
getSpan
public int getSpan() -
getLexeme
Get the raw lexeme of the current token.- Returns:
- Returns the underlying lexeme of the token.
-
getStringContents
Get the associated String contents of the token if it's a string, text block, or identifier.- Returns:
- Returns the string contents of the lexeme, or null if not a string|text block|identifier.
-
getErrorMessage
Gets the associated error message with the token if it's an error.- Returns:
- Returns the error message or null if not an error.
-
getNumberValue
Get the computedNumber
of the current token if it's a number.- Returns:
- Returns the computed Number or null if not a number.
-