Skip to content

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.

  • Indentation-sensitive blocks with exactly four spaces.
  • Top-level items: import, const, extern, struct, enum, impl, and def.
  • export makes a declaration importable from other modules (pub is an accepted legacy alias).
  • Line comments start with #.
import std.fs as fs
const BUF_SIZE: usize = 4096
  • import path.to.module imports a module namespace; reach items through qualified access (std.fs.open_read(path)).
  • import path.to.module as alias binds the namespace under an alias (fs.open_read(path)).
  • from path.to.module import Item imports selected exported items into bare scope.
  • const NAME: Type = expr declares a checked compile-time constant.
  • def name(params) -> Type: declares a function. Prefix with export to make it importable (pub is an accepted legacy alias).
  • unsafe def name(params) -> Type: declares a function whose callers must use an unsafe: 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_ssize
  • let name = expr: immutable local
  • let mut name = expr: mutable local (legacy form)
  • var name = expr: preferred sugar for mutable locals
  • place = expr: assignment to a mutable local, field, index, or auto-deref target
  • if / elif / else, while, for item in iterable, match subject:
  • return expr, return, break, continue
  • defer cleanup(): registers a cleanup call for the current lexical scope
  • use name = expr cleanup cleanup_call():: resource block with explicit cleanup
  • use mut name = expr:: shorthand for std resource types with a known best-effort cleanup
  • tasks:: structured task scope (see Concurrency)
  • 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 place remain 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.

Precedence is conventional:

ClassOperators
Unary-x, not x, ~x
Multiplicative*, /
Additive+, -
Shifts<<, >>
Bitwise&, ^, |
Comparisons<, <=, >, >=, ==, !=
Booleanand, or

Overshifts trap deterministically unless the checker proves the shift amount is in range.

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.