Syntax Overview
Novum uses a compact expression-oriented syntax.
Statements and expressions
Most constructs are expressions. Blocks evaluate their contained expressions and produce the value of the last successful expression.
{
x = 10
y = 20
x + y
}
Comments
The exact comment forms are lexer-defined. Keep comments consistent with the syntax accepted by the current lexer.
Identifiers
Identifiers are used for variables, functions, fields, modules, types, and parameters.
Literals
Common literals include:
42
3.14
true
false
"hello"
[1, 2, 3]
Calls
f(1, 2)
obj.method(1)
Named arguments are supported for user-defined functions, methods, and struct/class constructors:
f(y=3, x=2)
Point(x=2, y=3)
Positional arguments must precede named arguments:
f(1, y=2) // valid
f(x=1, 2) // invalid
Access
Field access:
object.field
Indexing:
xs[0]
d["key"]
Tuple indexing uses dot syntax where supported by the parser:
pair.0
Assignment
Simple assignment:
x = 10
Compound assignment:
x += 1
xs[0] += 1
object.value *= 2
Import aliases
import math as m
m.sqrt(16)