Reference

Lexical Structure & Layout

Write Unicode names, comments, and literals, and decide where an expression continues onto the next line.

Use this page to choose names and literal spellings, and to split an expression across lines. You will see when a newline ends a statement and when the expression continues.

Run a file with a multiline expression

Install Topaz, then save this as lexical-layout.tpz.

TOPAZ
import std.io

let ready = true
let archived = false
let missing = null
let 상태 = "ready"

let total =
    40 +
    2

io.writeLine("{상태}: {ready}, {archived}, {missing}, {total}")

Check and run it from the folder containing the file.

BASH
topaz check lexical-layout.tpz
topaz run lexical-layout.tpz

The check succeeds, and the program prints the following text.

Output
ready: true, false, null, 42

The first four declarations each fit on one line. The declaration of total spans three lines and produces 42. 상태 is a valid Unicode name. Keywords such as let, true, false, and null keep their English spelling.

Decide where to break a line

The lines ending in = and + need another value, so the total expression continues. Indentation helps you read the code. Delimiters and operators determine how the compiler groups it.

TaskWrite it this way
Finish a top-level declaration or block statementStart the next item on a new line
Continue arithmetic or a pipelineLeave the operator at the end of the previous line
Split arguments, collection elements, or record fieldsKeep the list inside its delimiters and use commas between entries
Make grouping explicitAdd parentheses

Newlines act as whitespace inside parentheses, brackets, record braces, and parameter or argument lists. Inside a block, match body, or concurrent body, a completed line can end an item.

You can also separate statements with ;. Use commas for list entries. An else on the next line still belongs to its if or timed concurrent expression. No explicit line-continuation character is needed.

Write names, comments, and literals

An identifier is a name such as total or 상태. It starts with a Unicode letter, _, or emoji. Following characters can also include Unicode digits. _internal is an ordinary name. A single _ discards a value in a pattern or marks an argument position in a pipeline. You cannot read it as a variable.

A literal writes a value directly, such as 42, true, null, or "ready".

TaskForm
Comment to the end of a line// comment
Comment across lines/* comment */, with no nested block comments
Write an integer or floatDecimal digits, such as 42 or 1.5
Write a hexadecimal or binary integer0x or 0b before the digits, such as 0xFF or 0b1010
Group digits_ between two digits, such as 1_000_000 or 0xFF_FF
Write textDouble quotes, with escapes such as \n and interpolation such as {total}
Write multiline textTriple quotes

You can write the prefixes and hexadecimal digits in either case, as in 0X1f. A hexadecimal or binary literal is an int. For a value above 0x7FFF_FFFF_FFFF_FFFF, topaz check reports TPZ5001.

Put each _ between two digits. topaz check reports TPZ2001 for 1_, 1__0, 0x_1F, a prefix with no digits such as 0x, and a digit outside the base such as 0b2 or 0x1G. The compiler reads _1 as a name because it starts with _.

Exponent notation such as 1e21 and octal literals such as 0o17 are unsupported. Write decimal digits or compute the value.

For triple-quoted text, every nonblank line must start with the whitespace prefix of closing quotes on a separate line. Strings & Templates explains the indentation rule, the public 5.20.3 interpreter behavior, and Unicode scalar access. Topaz does not normalize strings implicitly.

Correct an unexpected parse

If a calculation stops at a line break, check the position of + or -. At the start of a new statement, these signs can be unary operators applied to one value. Move the operator to the preceding line or enclose the expression in parentheses.

The compiler recognizes the longest valid token. It reads ?. as optional access. To access a member after Result propagation, write (expr?).field. Likewise, ... is distinct from the rest-pattern marker .. and the range operator ..<.

Use double quotes for strings. Single-quoted strings and character literals are unsupported. For text access, replace s[i] or s.length with Array operations on s.scalars(). Direct string slices and grapheme-cluster APIs are unavailable.

Continue with Operators & Expressions for grouping rules, Types for type annotations, or Unsupported Forms for other rejected spellings.