Language reference

Keywords, operators, literals, and quick lookup — everything the lexer and parser accept today.

Keywords

Full reserved-word list, @ raw identifiers, and #[…] attributes: Nyra Keywords.

KeywordPurpose
fnFunction definition
let / let mutImmutable / mutable binding
constCompile-time constant name
comptimeOptional compile-time evaluation — file module, #[comptime], or comptime { } block (guide)
if / elseConditional
whileLoop
for / inRange loop: for i in 0..10
returnReturn from function
matchPattern match on enums / values
struct / enumUser-defined types
implMethods on a type; impl Trait for Type
for (in types)HRTB binder: for<'a> fn(...)
importLoad another .ny file — import "path", as alias, or import { name } from "path"
moduleModule declaration (parsed)
extern / exportFFI declare / export symbol
testTest function
printBuilt-in stdout (keyword); optional color: for ANSI output
spawnConcurrent block
deferScope-exit call (LIFO) — Extended; prefer auto-drop / impl Drop
unsafeBlock for raw memory (deref, ptr arithmetic, raw casts)
asmInline assembly: asm "template" (inside unsafe)
asType cast: expr as Type; also import alias / selective rename
no_stdTop-level directive — skip runtime link; no print/spawn
move / cloneUnary prefixes at call sites — explicit move or clone
async / awaitStable Extended — promises + await; not on wasm32
trait / dynStable Extended — impl Trait for Type, trait objects dyn Trait
macroExtended — parsed and expanded
selfMethod receiver in impl

Built-in call names (no import)

Resolved in the typechecker like keywords. Full lookup: Built-in methods · Standard library → Built-ins.

String methods (no import): .length(), .split(), .trim(), .contains(), .replace(), .to_upper(), … — see Built-in methods → Strings.

Type names

Every type Nyra supports in source annotations and inference. All optional unless inference fails.

TypeOwnershipNotes
i8i128CopySigned integers; i32 default for int literals
u8u128CopyUnsigned integers
isize, usizeCopyPointer-sized integers
f32CopyIEEE-754 single (LLVM float); suffix f32
f64CopyIEEE-754 double (LLVM double); default float literal
charCopyUnicode scalar; 'a', '\n'
boolCopytrue / false
stringMoveUTF-8 bytes; literals static, heap values auto-dropped
VecStrCopy (handle).split(sep) result; for x in parts; optional annotation
voidFunction with no return value
ptrCopyOpaque FFI handle (Send)
*TCopyTyped raw pointer (!Send / !Sync)
&T / &mut TBorrowImmutable / mutable reference
&'a TBorrowExplicit lifetime on reference (Extended)
for<'a> fn(...)Higher-ranked function pointer type (Extended)
[T; N]Depends on TFixed-size array
(T, U, …)Depends on fieldsTuple
Vec<T>Depends on TStdlib growable vector (monomorphized)
StructNameCopy or MoveAuto-Copy when all fields Copy; Move if any field is Move
EnumNameCopyEnum tag + optional payload
option / resultCopyBuilt-in enum tags
T (generic param)Inferred at generic call site when omitted
Struct Send SyncThread-safety markers on struct declaration

Comments

FormExampleNotes
Line// comment to EOLCore — ignored by lexer
Block/* … */Core — multiline OK; non-nested; unclosed /* → lexer error
// file header
let x = 1 /* inline */ + 2
/*
 * multiline doc
 */

See Learn → Comments · Tests: tests/nyra/block_comments_test.ny · CONF-COMMENT-*

Literals

FormExampleType
Integer42, 0xff, 1_000_000, 255u8i32 (default) or suffix width
Float3.14, 1.5f32, 1e-3f64 default; f32 with suffix or annotation
Character'a', '\n'char
Booleantrue, falsebool
String"hello"string (static, not heap-freed)
Template`Hello, ${name}!`string (interpolates i32, f64, string)
Array[1, 2, 3], [0; 8], [-1; STROKE_MAX][i32; N] when annotated; repeat count may be a module const
Tuple(1, "a")(i32, string) when annotated

Template strings: backticks with ${expr} — e.g. `score: ${n}`. See Learn → Strings.

Numeric separators: underscores between digits are ignored — 10_00000 equals 100000. Hex integers: 0xFF, 0xffu8.

Operators

CategoryOperators
Arithmetic+ - * / %
Comparison== != < > <= >=ptr values compare string content (except function pointers)
Logical&& || !
Bitwise<< >> & | ^ (integers)
Nullish / optional?? ?. ?.method() — desugar to Option match; Option.Some(v) payload bind on ??
Reference&x (shared), &mut x (exclusive)
Raw (unsafe)*ptr load, *ptr = v store, ptr + i32, ptr - i32
Castexpr as Type — e.g. &x as *i32, ptr as i32
Fieldobj.field
Callf(a, b), obj.method(a)

Statements

Expressions

Unsafe & raw pointers

Nyra is safe by default. Low-level memory requires unsafe { }:

mut x = 42
unsafe {
    let p = &x as *i32
    *p = 99
    print(*p)
}
Inside unsafeOutside unsafe
*ptr load / *ptr = v store on *T or ptr&T / &mut T only
ptr + i32, ptr - i32Rejected
expr as *T, ptr as i32Safe casts only (no raw pointers)
Borrow checker bypassedFull NLL + move rules

ptr = opaque FFI handle. *T = typed raw pointer for drivers/MMIO. Inline asm: asm "nop" inside unsafe. OS APIs: import "stdlib/os.ny". See Memory → unsafe, Stdlib → os.

Ownership quick ref

ActionCopy type (i32)Move type (string heap)
let b = aBoth usablea invalidated
Pass to functionCopied (unless mut)Moved (unless mut)
Scope endStack discardAuto free if heap-owned
&a / &mut aNLL borrows — end at last use of refSame + auto-drop at scope
spawn { }Copy captures OKMove must be Send; moved into thread

Beginner track: Nyra OwnershipNyra Borrowing. Full rules: Memory & ownership. Developer UX: Ownership UX (auto-borrow, auto-Copy, inference).

Ownership UX

FeatureWhat you writeWhat the compiler does
Auto-borrowsave(user)save(&user) when param is &User
Auto-Copylet p2 = p1 on PointBoth bindings valid if all fields Copy
Return inferencefn f() { return 1 }Infers -> i32 or void
Generic call inferenceid(7)Monomorph id__i32
Cloneclone user or user.clone()Heap duplicate; binding kept
Movemove userExplicit move; skips auto-borrow

Diagnostics name the callee and suggest fixes. Conformance: CONF-INF-*, CONF-COERCE-*, CONF-DIAG-*, CONF-COPY-*, CONF-F64-*.

Lifetimes & HRTB

Traits (Drop)

impl Drop for MyType {
    fn drop(self) {
        // custom cleanup
    }
}

Drop and Clone are wired in the compiler. User traits: trait defs, impl Trait for Type, and dynamic dispatch via dyn Trait / value as dyn Trait (Extended MVP). See Traits & macros and examples/trait_dyn.ny.

Compiler pipeline

Source (.ny)
  → Lexer → Parser → Macro expand
  → Monomorph (+ generic call inference)
  → Auto-borrow coercion
  → Typecheck → Ownership (Copy inference) → Borrow + Lifetimes + Send/Sync
  → Drop plan → LLVM IR (f64/double, spawn, custom drop)
  → opt → clang + Nyra runtime → binary

Stop early: nyra check . or nyra diag .. See Toolchain.