v0.4.0

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
AsKeywordasLetKeywordlet
BreakKeywordbreakLoopKeywordloop
CatchKeywordcatchMatchKeywordmatch
ConstKeywordconstModuleKeywordmodule
ContinueKeywordcontinueMoveKeywordmove
DeferKeyworddeferNoneKeywordnone
DoKeyworddoNullKeywordnull
ElseKeywordelsePubKeywordpub
EnumKeywordenumReturnKeywordreturn
ExtendKeywordextendSelfKeywordself
ExternKeywordexternStructKeywordstruct
FailKeywordfailThrowKeywordthrow
FinallyKeywordfinallyThrowsKeywordthrows
ForKeywordforTryKeywordtry
FuncKeywordfuncTypeKeywordtype
IfKeywordifUnionKeywordunion
ImportKeywordimportUnsafeKeywordunsafe
InKeywordinVarKeywordvar
InterfaceKeywordinterfaceVariantKeywordvariant
IntrinsicKeywordintrinsicWhenKeywordwhen
IsKeywordisWhileKeywordwhile

Together with true and false, which are BoolLiteral tokens, these are the 44 reserved words. fail and finally are reserved but start nothing: fail value; is refused with help: write 'throw value;', and finally with help: use 'defer' inside the try block. See Keywords.

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<-Rejected
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
PlusPercent+%WrappingGreaterGreaterAssign>>=Assignment
MinusPercent-%WrappingGreaterGreaterGreaterAssign>>>=Assignment
StarPercent*%WrappingPlusPercentAssign+%=Assignment
MinusPercentAssign-%=Assignment
StarPercentAssign*%=Assignment

Operators and Punctuation says what each one means. <- is still read as a token only so that the parser can refuse it with the fix: ownership moves with move, as in let name = move source; and target = move source;.

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