Tokens

NEWLINE

A token that represents a new line.

Literals

A literal is an expression consisting of a single token, rather than a sequence of tokens, that immediately and directly denotes the value it evaluates to, rather than referring to it by name or some other evaluation rule. A literal is a form of constant expression, so is evaluated (primarily) at compile time.

Examples

Strings

ExampleCharactersEscapes
String"hello"ASCII subsetQuote & ASCII

ASCII escapes

Name
\nNewline
\rCarriage return
\tTab
\\Backslash

Quote escapes

Name
\"Double quote

Numbers

Number literals*Example
Decimal integer98_222
Hex integer0xff
Octal integer0o77
Binary integer0b1111_0000

* All number literals allow _ as a visual separator: 1_234

Boolean literals

Lexer
BOOLEAN_LITERAL :
   true | false

String literals

Lexer
STRING_LITERAL :
   " (
      PRINTABLE_ASCII_CHAR
      | QUOTE_ESCAPE
      | ASCII_ESCAPE
   )* "

PRINTABLE_ASCII_CHAR :
   Any ASCII character between 0x1F and 0x7E

QUOTE_ESCAPE :
   \"

ASCII_ESCAPE :
   | \n | \r | \t | \\

A string literal is a sequence of any characters that are in the set of printable ASCII characters as well as a set of defined escape sequences.

Line breaks are allowed in string literals.

Integer literals

Lexer
INTEGER_LITERAL :
   ( DEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL )

DEC_LITERAL :
   DEC_DIGIT (DEC_DIGIT|_)*

BIN_LITERAL :
   0b (BIN_DIGIT|_)* BIN_DIGIT (BIN_DIGIT|_)*

OCT_LITERAL :
   0o (OCT_DIGIT|_)* OCT_DIGIT (OCT_DIGIT|_)*

HEX_LITERAL :
   0x (HEX_DIGIT|_)* HEX_DIGIT (HEX_DIGIT|_)*

BIN_DIGIT : [0-1]

OCT_DIGIT : [0-7]

DEC_DIGIT : [0-9]

HEX_DIGIT : [0-9 a-f A-F]

An integer literal has one of four forms:

  • A decimal literal starts with a decimal digit and continues with any mixture of decimal digits and underscores.
  • A hex literal starts with the character sequence U+0030 U+0078 (0x) and continues as any mixture (with at least one digit) of hex digits and underscores.
  • An octal literal starts with the character sequence U+0030 U+006F (0o) and continues as any mixture (with at least one digit) of octal digits and underscores.
  • A binary literal starts with the character sequence U+0030 U+0062 (0b) and continues as any mixture (with at least one digit) of binary digits and underscores.

Examples of integer literals of various forms:

123                      // type u256
0xff                     // type u256
0o70                     // type u256
0b1111_1111_1001_0000    // type u256
0b1111_1111_1001_0000i64 // type u256