Skip to content

Token<TKind> Struct ​

Definition ​

A token produced by lexing a TextFile.

c#
public sealed struct Token<TKind> : IEquatable<Token<TKind>>
   where TKind : struct, Enum

View source

Type Parameters ​

NameDescription
TKindThe type of the enum that identifies the different kinds of token.

Constructors ​

NameDescription
Token(TKind, TextFile, Int32, Int32, Int32, Int32)Initialises a new instance of the Token<TKind> struct. No validation is performed for performance; use CreateToken<TKind>(TKind, SourceMark) to create tokens with guaranteed consistent values.

Properties ​

NameDescription
FileThe TextFile the token comes from.
KindThe kind of the token.
LengthThe length of the token.
PositionThe TextFilePosition of the token in File. The start index, line and column are clamped to valid positions in the file for tokens at positions a TextFilePosition cannot represent, that is, a token starting on a line's terminator or a zero length token at the end of the file.
StartColumnIndexZero based index of the start column of the token in File.
StartIndexThe index of the start of the token in File.
StartLineIndexZero based index of the start line of the token in File.
TextThe text of the token.

Methods ​

NameDescription
IsDirectlyBefore(Token<TKind>)Returns true if this token ends exactly where other starts, that is, the tokens are directly adjacent in the file with nothing between them. Both tokens are assumed to come from the same file.
ToString()Returns a string representation of this token, that is, the Kind followed by the Text if the token has any.