Lexical structure
Comments
// A line comment.
/* A block
comment. */
/// A documentation comment: describes the declaration right below it.
property opensAt: time = 18:00 "Opens"
/// is a documentation comment: it belongs to the declaration below it and becomes its
description and tooltip in the editor.
Lines and blocks
- The end of a line ends a statement; there are no semicolons.
- Line breaks inside parentheses, empty lines and lines holding only a comment are ignored.
- Every block closes with a single
end. A missingendis reported with the kind of block that was opened and its line.
if hasPower
decide()
end
Case
Kalem is case-sensitive. Script, host type and state names are PascalCase
(BusinessHours, Open); other names are camelCase (opensAt, hasPower).
Reserved words
server client script extends group property memory reads writes input timer daily every
at after on ready enter exit migrate function state auto goto start stop let var if then
elseif else end while for in to break continue return and or not true false as
- Type names are reserved too:
bool int float string time duration color. - Reserved for the next version:
task run cancel wait until timeout checkpoint scope send ref none struct list map. - These mean something only in their own declaration and may be names elsewhere:
label category version range step hidden was.
Names
- A name starts with a letter or
_and goes on with letters, digits and_. - Contract field and event names are dotted:
business.open,city.powerChanged. The parts after a dot may be reserved words (light.color,door.state); the first part may not. - A name resolves first to the declared fields and the catalog's events.
- There is no shadowing. A local or a parameter cannot have the name of anything declared
at the script's level (a property, memory, a function), of the standard library, or of the
first part of a declared dotted name (
business).
Literals
| Type | Example | Note |
|---|---|---|
int | 42, 0x2A, 1_000 | |
float | 0.7, 1.5e3 | digits on both sides of the point |
string | "Opens", "line\n" | escapes \n \t \\ \" \{; {expression} inserts a value |
bool | true, false | |
time | 18:00, 03:30 | minute of the day (0–1439); shown as HH:MM in the editor |
duration | 30m, 2h, 1d, 1h30m | whole minutes |
color | #ffd580, #ffd58080 | RGB (alpha 1) or RGBA; channel = hex value / 255 |
In a string, {expression} inserts that expression's value:
"{business.visitors} visitors today". A brace itself is written \{.