Syntax overview
The current Zmeu surface in one page: file shape, declarations, statements, expressions.
This page maps the active Zmeu surface syntax. It is descriptive: it tracks the accepted language, not the design backlog.
File shape
Section titled “File shape”- Indentation-sensitive blocks with exactly four spaces.
- Top-level items:
import,const,extern,struct,enum,impl, anddef. exportmakes a declaration importable from other modules (pubis an accepted legacy alias).- Line comments start with
#.
import std.fs as fsconst BUF_SIZE: usize = 4096Declarations
Section titled “Declarations”import path.to.moduleimports a module namespace; reach items through qualified access (std.fs.open_read(path)).import path.to.module as aliasbinds the namespace under an alias (fs.open_read(path)).from path.to.module import Itemimports selected exported items into bare scope.const NAME: Type = exprdeclares a checked compile-time constant.def name(params) -> Type:declares a function. Prefix withexportto make it importable (pubis an accepted legacy alias).unsafe def name(params) -> Type:declares a function whose callers must use anunsafe:block.def name[T, E](...) -> Type:declares an explicitly-instantiated generic function.extern "C":declares bodyless C ABI functions.
def identity[T](value: T) -> T: return value
extern "C": def write(fd: c_int, buf: *const u8, len: usize) -> c_ssizeStatements
Section titled “Statements”let name = expr: immutable locallet mut name = expr: mutable local (legacy form)var name = expr: preferred sugar for mutable localsplace = expr: assignment to a mutable local, field, index, or auto-deref targetif/elif/else,while,for item in iterable,match subject:return expr,return,break,continuedefer cleanup(): registers a cleanup call for the current lexical scopeuse name = expr cleanup cleanup_call():: resource block with explicit cleanupuse mut name = expr:: shorthand for std resource types with a known best-effort cleanuptasks:: structured task scope (see Concurrency)
Expressions
Section titled “Expressions”- Literals: integers (decimal + hex), strings (
"..."), byte strings (b"HTTP\r\n"), byte literals (b'\n'),true,false,None. - Calls, methods, indexing, slicing:
f(a),x.method(a),xs[i],xs[start:end],xs[:]. - Method chains may continue on indented lines that start with
.. - Generic calls require explicit type arguments:
identity[i32](1). - Struct literals and enum constructors use named payloads:
Point(x=1, y=2),Ok(value=bytes). - View expressions:
view place,mut view place. (&place,&mut placeremain accepted compatibility syntax.) - Raw extern views:
raw ptr bytes,raw mut ptr buf,raw cstr "name",raw cstr view. - Result propagation:
try expr. - Casts:
expr as Type. - Type tests:
x is None,x is not None,x is i32,x is not Point.
Operators
Section titled “Operators”Precedence is conventional:
| Class | Operators |
|---|---|
| Unary | -x, not x, ~x |
| Multiplicative | *, / |
| Additive | +, - |
| Shifts | <<, >> |
| Bitwise | &, ^, | |
| Comparisons | <, <=, >, >=, ==, != |
| Boolean | and, or |
Overshifts trap deterministically unless the checker proves the shift amount is in range.
What’s next
Section titled “What’s next”The pages under Language unpack each piece in more detail. Standard library documents the modules under std.*. Examples is a gallery of small annotated programs.