NIAOJoin Beta

Language Reference

Keywords, types, operators, and core syntax for Niao v0.1

Keywords

Reserved words in the Niao grammar. Use struct for plain data and class when you need methods and inheritance.

Declarations

fn
Define a function
let
Declare a variable
struct
Data-only record type (no methods)
class
OOP type with fields and methods
trait
Method contract (signatures only)
import
Load a module
as
Alias an import
static
Static field or method on a class

Control flow

if
Conditional branch
else
Alternative branch
while
Loop while condition is true
for
Iterate with for-in
in
Used in for-in loops
return
Return from a function
break
Exit a loop
continue
Skip to next loop iteration

Error handling

try
Begin a protected block
catch
Handle thrown errors
throw
Raise an error value

Object-oriented

extends
Single inheritance from a parent class
implements
Adopt one or more traits
self
First parameter of instance methods (required)
super
Call a parent class method
public
Member visible everywhere (default)
private
Member only accessible inside the class body

Web DSL

Top-level constructs for HTTP servers and routes.

server
Server configuration block
GET
HTTP GET route
POST
HTTP POST route
PUT
HTTP PUT route
DELETE
HTTP DELETE route
PATCH
HTTP PATCH route

Literals

true
Boolean true
false
Boolean false
nil
Null / absent value

Types

Primitive type annotations. Custom type names and class names are also valid in signatures.

TypeDescription
intInteger numbers
floatFloating-point numbers
stringUTF-8 text
booltrue or false
voidNo return value
errorStructured error values

Operators

Assignment

=+=-=

Logical

||&&!

Comparison

==!=<><=>=

Arithmetic

+-*/%

Unary

!-

Member & indexing

.()[]

Call functions, access fields, and index arrays.

Core builtins

Built-in functions available without importing a module.

SignatureDescription
type(x)Type name string; class instances return their class name
has_trait(x, "TraitName")true if the instance's class implements the trait
is_error(x)true if value is a structured error
print(...)Write to stdout
len(x)Length of string or array
assert(cond, msg?)Abort if condition is false

Example

Structs for data, classes for behavior, and standard imports for stdlib modules.

structs, classes, and imports

structs, classes, and imports
import "json"
fn greet(name: string) -> string {
return "Hello, " + name
}
struct User {
name: string
age: int
}
class Greeter {
fn hello(self, user: User) -> string {
return greet(user.name)
}
}
fn main() {
let user = User { name: "Niao", age: 1 }
let g = Greeter {}
print(g.hello(user))
}

Next steps

Browse the standard library modules for full API references - HTTP frameworks, databases, ML, and core utilities.

Explore the ecosystem →