Literals and values
This page covers literal forms and direct value constructors accepted by the parser.
Integer literals
Accepted forms:
42
0
123456
The parser also accepts radix-prefixed integer literals:
0xff
0b101010
These are parsed as integer values.
Floating-point literals
Accepted form:
3.14
0.5
12.0
Boolean literals
Accepted forms:
true
false
None literal
Draton accepts the None literal:
let value = None
Use it where the surrounding type or contract makes the intended optional/nullish shape clear.
String literals
Basic string literals:
"hello"
"draton"
Interpolated string literals
Draton supports f-strings:
let name = "Minh"
let greeting = f"Hello {name}"
Interpolation rules, as currently implemented:
- the outer literal starts with
f" - literal fragments and embedded expressions can be mixed
- each
{ ... }section is parsed as a real expression
Tuple literals
Accepted forms:
(1, 2)
(1, 2, 3)
()
Parenthesized single expressions stay grouped expressions, not tuples:
(x + 1)
Array literals
Accepted form:
[1, 2, 3]
[]
Map literals
Brace literals with key: value entries are maps:
{ "a": 1, "b": 2 }
{}
The empty brace literal is currently parsed as an empty map.
Set literals
Brace literals without : are sets:
{ 1, 2, 3 }
{ "a", "b" }
Result constructors
Ok(...) and Err(...) are recognized specially when called with exactly one argument:
Ok(42)
Err("bad input")
Channel type constructor expression
Draton also parses chan[T] at expression level as a channel constructor/type-form expression:
let jobs = chan[Int]
See Concurrency and channels for the current syntax boundary.