Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Lexical structure

A source file is Unicode text. The lexer reads one file at a time, so a string or a comment left open is reported in the file that opened it.

Comments

// to the end of the line
/* block comments nest /* like this */ */

Comments and blank lines are kept by slc fmt.

Identifiers

An identifier starts with a letter or _ and continues with letters, digits, or _. Letters are Unicode letters.

return, if, else, true, and false are ordinary identifiers. True and False are the variants of Bool. In a handler clause, return followed by ( is the body's result: return(x) => e.

Keywords

These words are tokens:

WordRole
func, proc, fnFunctions. func names one, fn is a lambda, proc is a command
data, enum, menu, formType declarations
spec, impl, forTraits
hook, do, hand, hn, resetEffects and handlers
of, mu, letMatching, consumers, binding
sect, citeSections
def, pub, dualA constant, visibility, the dual of a type

let+ and let- are let with a sign touching the keyword.

The lambda stays fn. A named function is func. The migration note is docs/MIGRATION.md. Words it records, such as command and mod, are ordinary identifiers.

Literals

LiteralType when unconstrainedExample
integeri6442, 1_000, -7
floatf641.5, -0.5
stringString"hello\n"
characterchar'A', '\n'

An integer or float literal takes a narrower type when the port it meets requires one. A minus sign is part of the literal only when it touches the digits. _ inside a number is ignored. A number that does not fit in 64 bits is a lex error.

String and character escapes are \n, \t, \r, \0, \\, \", and \'. An unknown escape is a lex error.

Punctuation

Arrows: ->, <-, =>, <=. Paths: ::. Ranges in patterns: ..=. The flow marks are <, |, and >. Type and effect rows use / and .., as in / {IO} and ..E. +, -, and * are signs on a type, and + and - also mark let+ and let-. A - that touches a number is part of that literal. @ binds a pattern: name @ pattern.

<= is the demand arrow, in a mu arm and in a chain binder k <= e. !, %, ==, !=, >=, &&, ||, and the brackets ⟨ ⟩ are not tokens.