Token
A token consisting of itsPosition and a TokenType.
Methods
new
Creates a token with a zero position.
start_position
The position a token begins at.
end_position
The position a token ends at.
token_type
The type of token as well as the data needed to represent it. If you don’t need any other information, use token_kind instead.
token_kind
The kind of token with no additional data. If you need any information such as identifier names, use token_type instead.
TokenType
The type of tokens in parsed code.Methods
is_trivia
Returns whether a token can be practically ignored in most cases. Comments and whitespace will return true, everything else will return false.
kind
Returns the kind of the token type.
spaces
Returns a whitespace TokenType consisting of spaces.
tabs
Returns a whitespace TokenType consisting of tabs.
TokenKind
The kind of token. Contains no additional data.TokenReference
A reference to a token used by ASTs. Dereferences to aToken.
TokenReferences include “trivia” - leading and trailing whitespace and comments that are attached to the token but don’t affect its meaning.
Methods
new
Creates a TokenReference from leading/trailing trivia as well as the leading token.
symbol
Returns a symbol with the leading and trailing whitespace. Only whitespace is supported.
symbol_specific_lua_version
Returns a symbol with the leading and trailing whitespace, much like TokenReference::symbol, but only if it’s valid for the given Lua version.
token
Returns the inner token.
leading_trivia
Returns the leading trivia.
trailing_trivia
Returns the trailing trivia.
with_token
Creates a clone of the current TokenReference with the new inner token, preserving trivia.
is_symbol
Checks if the token is the given symbol.
Symbol
A literal symbol, used for both words important to syntax (likewhile) and operators (like +).