Class Token
java.lang.Object
com.oracle.js.parser.Token
A token is a 64 bit long value that represents a basic parse/lex unit. This class provides static
methods to manipulate lexer tokens.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intWe use 28 bits for the position and 28 bits for the length of the token. -
Method Summary
Modifier and TypeMethodDescriptionstatic intdescLength(long token) Extract token length from a token descriptor.static intdescPosition(long token) Extract token position from a token descriptor.static TokenTypedescType(long token) Extract token type from a token descriptor.static longChange the token to use a new type.static longCreate a compact form of token information.static StringString conversion of tokenstatic StringReturn a string representation of a token.static longwithDelimiter(long token) Normally returns the token itself, except in case of string tokens which report their position past their opening delimiter and thus need to have position and length adjusted.
-
Field Details
-
LENGTH_MASK
public static final int LENGTH_MASKWe use 28 bits for the position and 28 bits for the length of the token. This limits the maximal length of code we can handle to 2 ^ 28 - 1 bytes.- See Also:
-
-
Method Details
-
toDesc
Create a compact form of token information.- Parameters:
type- Type of token.position- Start position of the token in the source.length- Length of the token.- Returns:
- Token descriptor.
-
descPosition
public static int descPosition(long token) Extract token position from a token descriptor.- Parameters:
token- Token descriptor.- Returns:
- Start position of the token in the source.
-
withDelimiter
public static long withDelimiter(long token) Normally returns the token itself, except in case of string tokens which report their position past their opening delimiter and thus need to have position and length adjusted.- Parameters:
token- Token descriptor.- Returns:
- same or adjusted token.
-
descLength
public static int descLength(long token) Extract token length from a token descriptor.- Parameters:
token- Token descriptor.- Returns:
- Length of the token.
-
descType
Extract token type from a token descriptor.- Parameters:
token- Token descriptor.- Returns:
- Type of token.
-
recast
Change the token to use a new type.- Parameters:
token- The original token.newType- The new token type.- Returns:
- The recast token.
-
toString
-
toString
-