Syntax and comments
The lexical structure of a Sarlin source file.
Statements and blocks
Sarlin statements do not end with semicolons. Whitespace separates tokens, while braces delimit function bodies, branches, loops, classes and defines. Parentheses group expressions and contain function arguments.
Identifiers
An identifier starts with an ASCII letter or underscore and continues with ASCII letters, digits or underscores. Names are case-sensitive. The examples use PascalCasefor classes and defines and snake_case for values and functions.
Literals
Sarlin has integer literals, decimal floating-point literals, the booleanstrue and false, and double-quoted strings. Strings occupy one source line and currently have no escape syntax. Arrays and dictionaries use bracket literals; they are covered on the Collections page.
Comments and documentation
#### File documentation appears before every declaration.
# A normal line comment.
###
A multiline comment starts and ends with three hashes
on lines of their own.
###
## Documentation attached to main.
func main() {
print("Hello") # Comments may follow code.
}#begins a normal comment.##documents the declaration immediately following it.###delimits a multiline comment.####records file documentation and must precede all declarations.
Expressions and operators
func main() {
local var total int32 = (4 + 2) * 3
local var ready bool = total >= 10 and not false
local var message string = "Total: " + total
print(message)
print(ready)
}| Precedence | Operation | Syntax |
|---|---|---|
| 1 (higher first) | Member access, calls, indexing | value.member, function(), values[index] |
| 2 (higher first) | Logical not | not |
| 3 (higher first) | Multiply, divide, modulo | *, /, % |
| 4 (higher first) | Add, subtract | +, - |
| 5 (higher first) | Comparison | >, >=, <, <= |
| 6 (higher first) | Equality | ==, != |
| 7 (higher first) | Logical and | and |
| 8 (higher first) | Logical or | or |
Arithmetic requires numeric operands. Comparisons produce booleans. Logical operators require booleans. Addition concatenates strings and automatically converts primitive numeric and boolean operands when a string is required.