Strings
Single and double quotes are interchangeable; both support interpolation, escape sequences, format specs, and raw variants.
Summary
Expressions inside {braces} are evaluated and embedded inline. An optional :specafter the expression controls formatting, following Python's mini-language for width, alignment, precision, and base. Triple-quoted strings handle multi-line text with automatic indentation stripping. Raw strings (r"...") skip all escape processing and interpolation. Color strings (c"bold;red;text") embed ANSI sequences at parse time. Concatenation uses ++.
Canonical
Both single and double quotes create strings. They're identical: both support interpolation and escape sequences.
let s = "hello world"
let s2 = 'also a string'Interpolation
Expressions inside {braces} are evaluated and embedded.
let name = "XS"
println("Hello, {name}!") -- Hello, XS!
println("{1 + 2} is three") -- 3 is three
println("{name} has {len(name)} chars") -- XS has 2 chars
-- escape the brace to get a literal {
println("\{not interpolated}") -- {not interpolated}Format Specs
After the expression, an optional :spec controls how the value is rendered. Spec syntax follows Python's mini-language: {value:[fill][align][width][,][.prec][type]}.
let pi = 3.14159
println("{pi:.2}") -- 3.14
println("{pi:8.2}") -- " 3.14"
println("{pi:<8.2}") -- "3.14 "
println("{pi:^8.2}") -- " 3.14 "
println("{pi:.2%}") -- 314.16%
let n = 1234567
println("{n:,}") -- 1,234,567
println("{255:x}") -- ff
println("{255:X}") -- FF
println("{8:b}") -- 1000
println("{8:o}") -- 10
-- Fill char before the alignment marker
println("{42:0>5}") -- 00042Escape Sequences
| Escape | Character |
|---|---|
\n | Newline |
\t | Tab |
\r | Carriage return |
\\ | Backslash |
\" | Double quote |
\' | Single quote |
\0 | Null byte |
\a | Bell |
\b | Backspace |
\f | Form feed |
\v | Vertical tab |
\e | ESC (0x1B) |
\{ | Literal { (suppresses interpolation) |
Any other \x passes through unchanged.
Triple-Quoted Strings
Multi-line strings with automatic indentation handling.
let text = """
line one
line two
"""
println(text.contains("\n")) -- trueTriple-quoted strings still support interpolation. Use r"""...""" for raw triple-quoted.
Raw Strings
No escape processing, no interpolation.
let pattern = r"\d+\.\d+"
println(pattern) -- \d+\.\d+
let x = 42
let raw = r"no {x} here \n raw"
println(raw) -- no {x} here \n rawColor Strings
Embed ANSI terminal colors at parse time. Format: c"style;style;...;text": the last segment is the text, everything before it is styling.
let err = c"bold;red;Error!"
let ok = c"green;Success"
println(err) -- prints "Error!" in bold redA reset sequence is appended automatically.
Available styles:
| Category | Values |
|---|---|
| Attributes | bold, dim, italic, underline, blink, reverse, hidden, strikethrough |
| Foreground | black, red, green, yellow, blue, magenta, cyan, white |
| Bright FG | bright_black, bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white |
| Background | bg_black, bg_red, bg_green, bg_yellow, bg_blue, bg_magenta, bg_cyan, bg_white |
| Bright BG | bg_bright_black, bg_bright_red, etc. |
| 256-color | fg256,N, bg256,N (N = 0-255) |
| Truecolor | rgb,R,G,B, bgrgb,R,G,B |
Color strings support interpolation in the text part: c"bold;x = {x}".
String Concatenation
"hello" ++ " world" -- "hello world"
"a" ++ "b" ++ "c" -- "abc"Strings concatenate with either ++ or +; ++ is the canonical form so it's clear at the call site that the operands are strings.