1.5 Literals
| Kind | Syntax | Default type |
|---|---|---|
| Integer | 42, 1_000, 0xFF, 0o17, 0b1010, suffix 42u8 | inferred; otherwise i64 |
| Floating-point | 3.14, 1e-9, 2.5f32 | inferred; otherwise f64 |
| Boolean | true, false | bool |
| Character | 'a', '\n', '\u{1F600}' | char |
| String | "text {expr}" | str |
| Raw string | r"C:\path", r#"..."# | str |
| Multi-line | """…""" (the common indentation is removed) | str |
| Bytes | b"\x00abc" | bytes |
| Duration | 250ms, 1h30m, 2d, 1.5s | Duration |
| Size | 512B, 4KiB, 16MiB, 1GB | u64 (bytes) |
| Date | 2026-11-03 | Date |
| Date-time | 2026-11-03T18:00, 2026-11-03T18:00:05.250 | LocalDateTime |
| UTC instant | 2026-11-03T15:00Z | Time |
| Prefixed | re"\d+", tz"Europe/Moscow", cron"0 9 * * MON-FRI", sha256"ab12…", ip"10.0.0.1" | the handler's type |
| Absence | none | none |
| Unit | () | () |
Rules:
- Interpolation
{expr}in a string evaluatesexprand callsShow.show. A literal curly brace is{{and}}. Format:{x:.2},{x:08x},{t:dd.MM.yyyy}(§17.5). The specifier{expression:spec}:spec = [[fill]align][sign][#][0][width][.precision][type]; alignment<,^,>(numbers —>, text —<); sign+or-;#— the radix prefix (0x,0o,0b);0— zero padding (numbers only);.N— the number of fraction digits for floating-point values and the length (in characters) for text. Type: integers —x X o b; floating-point —e E;str,char—?(quoted with escaping);Duration— a unitns us ms s m h d: the value in these units followed by the suffix ({d:ms}→1500ms,{d:.2s}→1.50s);Time,LocalDateTime,Date— a pattern (§17.5); a type with a methodfmt(spec: str) -> str— a custom format. A specifier that does not fit the type of the value is the compile errorbad-format-spec; for types unknown at checking time (a generic parameter) only the syntax is checked (D-8064; D-7810). - Escape sequences:
\n \r \t \\ \" \' \0 \xHH \u{H…}. - Duration units:
ns us ms s m h d. A compound duration has the units in strictly descending order, without spaces (1h30m15s). Calendar intervals (months, years) are not literals butPeriod(§17.2). - Dates and date-times are recognised by the lexer greedily by the pattern
DDDD-DD-DD[TDD:DD[:DD[.D+]]][Z]. Subtraction of numbers is written with spaces:2026 - 11. - A prefixed literal
p"…"calls the comptime functionliteral fn p(s: str) -> Tfrom the scope (§15.3). An error in the handler is a compile error. Built-in prefixes:r b re tz cron sha256 ip urlhtml. - An integer literal that does not fit the inferred type is a compile error.
Related diagnostics
bad-format-spec, invalid-char-literal, invalid-date, invalid-duration, invalid-escape, invalid-number, literal-overflow, unterminated-string
See also
Source: docs/spec/oxl-standard.en.md