Modules and Imports
Import Syntax
Braid uses import statements to bring in code from other modules. The syntax uses dot-separated module paths that correspond to the file system layout.
import std.io;
import std.math;
import std.time;
import std.async;
fn main() {
print("hello");
}Dot Notation for Module Paths
Module paths use dots as separators. The path std.io maps to the filestd/io.br (or std/io.bd, std/io.bx). Each dot corresponds to a directory level.
import ui.widget;
import ui.layout;
import ui.render;
import ui.theme;
import db.models.user;
import db.models.post;
import db.queries;Module Resolution
The compiler resolves import paths by searching for files in the following order:
.br— Braid source file.bd— Braid script file.bx— Braid bytecode artifact
The search starts from the directory of the importing file and also checks the standard library path and any configured include paths.
import std.io; // resolves to std/io.br, std/io.bd, or std/io.bx
import std.math; // resolves to std/math.br
import db.models.user; // resolves to db/models/user.brStandard Library Modules
The Braid standard library provides commonly used modules under the stdprefix.
import std.io; // print, read, file I/O functions
import std.math; // math functions (sqrt, sin, cos, etc.)
import std.time; // dates, timers, duration functions
import std.async; // async runtime, channels, spawn
fn main() {
let now = std.time.now();
let val = std.math.sqrt(16.0);
std.io.print("sqrt: " + val);
}Struct and Function Imports
Importing a module makes all top-level definitions available. You reference them by their full path or by their local name after import.
import geometry.shapes;
fn main() {
let rect = geometry.shapes.Rectangle { width: 10, height: 5 };
let area = rect.width * rect.height;
print(area);
}How the Parser Handles Imports
The parser processes import at the top level of a file. It reads the dot-separated path, reconstructs the full module string, and emits anAST_IMPORT node. The VM then resolves and loads the module at runtime.
import config.app;
import config.database;
import config.routes;
fn main() {
let app_name = config.app.name;
let db_url = config.database.url;
print("starting " + app_name);
}Nested Imports and Organization
Organize your code into nested module directories to keep projects manageable. Each directory corresponds to a dot-separated segment in the import path.
// File structure:
// src/
// main.br
// models/
// user.br
// post.br
// services/
// auth.br
// email.br
// In main.br:
import models.user;
import models.post;
import services.auth;
import services.email;