Skip to content

Command Definitions

Comment /* */ or //
Boolean true, false
Integer 42, 0x2A, 0o52, 0b101010
Decimal 0.5, .5
String "foo", 'bar'
Array [1, 2, 3]
Map {a: 1, b: 2, c: 3}
Null nil

Strings can be enclosed in single or double quotes. They can contain escape sequences, such as \n for newline, \t for tab, \uXXXX for Unicode code points.

"Hello\nWorld"

For multiline strings, use backticks:

`Hello
World`

Backtick strings are raw strings, they don’t support escape sequences.

Arithmetic +, -, *, /, % (modulo), ^ or ** (exponent)
Comparison ==, !=, <, >, <=, >=
Logical not or !, and or &&, or or ||
Conditional ?: (ternary), ?? (null coalescing), if {} else {} (multiline)
Membership [], ., ?., in
String + (concatenation), contains, startsWith, endsWith
Regular Expression matches
Range ..
Slice [:]
Pipeline |

Structure fields and map elements can be accessed with the . operator or the [] operator. The following two expressions are equivalent:

user.Name
user["Name"]

Array and slice elements can be accessed with the [] operator. Negative indices are supported, with -1 being the last element.

array[0] // first element
array[-1] // last element

The in operator can be used to check if an element is in an array or a map.

"John" in ["John", "Jane"]
"name" in {"name": "John", "age": 30}

The ?. operator can be used to access a structure field or map element without checking if the structure or map is nil. If the structure or map is nil, the result of the expression is nil.

author.User?.Name

Is equivalent to:

author.User != nil ? author.User.Name : nil

The ?? operator can be used to return the left side if it’s not nil, otherwise return the right side.

author.User?.Name ?? "Anonymous"

Is equivalent to:

author.User != nil ? author.User.Name : "Anonymous"

The slice operator can be used to extract a portion of an array or string. The syntax is [start:end], where start and end are optional. If start is omitted, it defaults to 0. If end is omitted, it defaults to the length of the array or string. Negative indices are supported.

array[1:3] // elements at index 1 and 2
array[:3] // first three elements
array[1:] // all elements starting from index 1
array[-2:] // last two elements

String formatting is done with the format function:

format("Hello %s", "World")
format("Number: %d", 42)
format("Float: %.2f", 3.14159)

The following format specifiers are supported:

%s String
%d Integer
%f Float
%t Boolean
%v Any value

For floating point numbers, you can specify the precision with .N where N is the number of decimal places:

format("%.2f", 3.14159) // "3.14"

You can also specify the width of the field with a number before the format specifier:

format("%5d", 42) // " 42"
format("%-5d", 42) // "42 " (left-aligned)
format("%05d", 42) // "00042" (zero-padded)