Modules
Every source file defines one module.
Module Names
| File Path | Module Name |
|---|---|
src/main.ori | main |
src/math.ori | math |
src/http/client.ori | http.client |
src/http/mod.ori | http |
Imports
import = "use" import_path [ import_list | "as" identifier ] .
import_path = string_literal | identifier { "." identifier } .
import_list = "{" import_item { "," import_item } "}" .
import_item = [ "::" ] identifier [ "as" identifier ] | "$" identifier .
Relative (Local Files)
use './math' { add, subtract }
use '../utils/helpers' { format }
Paths start with ./ or ../, resolve from current file, omit .ori.
Module (Stdlib/Packages)
use std.math { sqrt, abs }
use std.net.http as http
Private Access
use './math' { ::internal_helper }
:: prefix imports private (non-pub) items.
Aliases
use './math' { add as plus }
use std.collections { HashMap as Map }
Visibility
Items are private by default. pub exports:
pub @add (a: int, b: int) -> int = a + b
pub type User = { id: int, name: str }
pub $timeout = 30s
Re-exports
pub use './client' { get, post }
Extensions
Definition
extension_def = "extend" identifier [ where ] "{" { method } "}" .
extend Iterator {
@count (self) -> int = ...
}
extend Iterator where Self.Item: Add {
@sum (self) -> Self.Item = ...
}
Import
extension_import = "extension" import_path "{" trait "." method { "," trait "." method } "}" .
extension std.iter.extensions { Iterator.count, Iterator.last }
extension './my_ext' { Iterator.sum }
Method-level granularity required; no wildcards.
Resolution
- Local bindings (inner first)
- Function parameters
- Module-level items
- Imports
- Prelude
Circular dependencies prohibited.
Prelude
Available without import:
Types: int, float, bool, str, char, byte, void, Never, Duration, Size, Option<T>, Result<T, E>, Ordering, Error, Range<T>, Set<T>, Channel<T>, [T], {K: V}
Functions: print, len, is_empty, is_some, is_none, is_ok, is_err, int, float, str, byte, compare, min, max, panic, all assertions
Traits: Eq, Comparable, Hashable, Printable, Clone, Default
Standard Library
| Module | Description |
|---|---|
std.math | Mathematical functions |
std.io | I/O traits |
std.fs | Filesystem |
std.net.http | HTTP |
std.time | Date/time |
std.json | JSON |
std.crypto | Cryptography |
Test Modules
Tests in _test/ with .test.ori extension can access private items:
src/
math.ori
_test/
math.test.ori
Package Manifest
[project]
name = "my_project"
version = "0.1.0"
[dependencies]
some_lib = "1.0.0"
Entry point: @main function.