Token Reference

The lexer turns a source file into a sequence of tokens, reading each one by the longest-match rule. This page lists every token kind under the name the compiler gives it.

Literals

TokenExamplesSee
IntLiteral42, 0xFF, 0o77, 0b1010, 200u8Integer literals
FloatLiteral3.14, 1.0e-9, 0.5f32Floating-point literals
StringLiteral"hello", c8"hello", c16"hello", c32"hello"String literals
CharLiteral'A', '\n', c8'A', c16'A', c32'A', c64'A', c128'A', c256'A', c512'A'Character literals
BoolLiteraltrue, falseBoolean literals

A numeric suffix and a character or string prefix are part of the literal's token.

Identifiers

TokenExamples
Identifiercount, Point, _tmp

Contextual words such as asm, sizeof and Self are identifiers to the lexer; see Keywords.

Keywords

TokenSpellingTokenSpelling
AsKeywordasInterfaceKeywordinterface
BreakKeywordbreakIntrinsicKeywordintrinsic
CatchKeywordcatchIsKeywordis
ConstKeywordconstLetKeywordlet
ContinueKeywordcontinueLoopKeywordloop
DeferKeyworddeferMatchKeywordmatch
DoKeyworddoModuleKeywordmodule
ElseKeywordelseNoneKeywordnone
EnumKeywordenumNullKeywordnull
ExtendKeywordextendPubKeywordpub
ExternKeywordexternReturnKeywordreturn
FailKeywordfailSelfKeywordself
ForKeywordforStructKeywordstruct
FuncKeywordfuncTypeKeywordtype
IfKeywordifUnionKeywordunion
ImportKeywordimportVarKeywordvar
InKeywordinVariantKeywordvariant
WhenKeywordwhen
WhileKeywordwhile

Together with true and false, which are BoolLiteral tokens, these are the 38 reserved words.

Punctuation

TokenSpellingTokenSpelling
LeftParen(Dot.
RightParen)DotDot..
LeftBrace{DotDotDot...
RightBrace}DotDotEqual..=
LeftBracket[Arrow->
RightBracket]FatArrow=>
Comma,At@
Semicolon;Hash#
Colon:Question?
ColonColon::QuestionQuestion??

Operators

TokenSpellingGroupTokenSpellingGroup
Plus+ArithmeticEqual==Comparison
Minus-ArithmeticBangEqual!=Comparison
Star*ArithmeticLess<Comparison
Slash/ArithmeticLessEqual<=Comparison
Percent%ArithmeticGreater>Comparison
PlusPlus++ArithmeticGreaterEqual>=Comparison
MinusMinus--ArithmeticMoveArrow<-Assignment
Amp&BitwiseAssign=Assignment
Pipe|BitwisePlusAssign+=Assignment
Caret^BitwiseMinusAssign-=Assignment
Tilde~BitwiseStarAssign*=Assignment
LessLess<<BitwiseSlashAssign/=Assignment
GreaterGreater>>BitwisePercentAssign%=Assignment
GreaterGreaterGreater>>>BitwiseAmpAssign&=Assignment
AmpAmp&&LogicalPipeAssign|=Assignment
PipePipe||LogicalCaretAssign^=Assignment
Bang!LogicalLessLessAssign<<=Assignment
GreaterGreaterAssign>>=Assignment
GreaterGreaterGreaterAssign>>>=Assignment

Operators and Punctuation says what each one means.

Special tokens

TokenMeaning
DocCommentA documentation comment, /// … or /** … */, kept so the parser can attach it to the next declaration. Ordinary comments produce no token.
EndOfFileAppended after the last token of every file
UnknownA character that starts no token, kept so the error can quote it
NewLineDefined but never produced: line breaks are whitespace

See also