Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.brim-lang.com/llms.txt

Use this file to discover all available pages before exploring further.

This page maps declaration syntax directly from grammar.ebnf.

Modules and imports

module_decl = "module" module_path separator? ;
module_path = identifier { "." identifier } ;
import_decl = "export"? "import" import_tree separator? ;
import_block = "imports" block_open import_block_entry_list? block_close ;
import_tree = import_path import_tree_suffix? ;
import_tree_suffix = import_alias | import_group | import_wildcard ;
Examples from the grammar:
import std.io
import std.io.*
import std.path.{Path, PathBuf}

imports {
  std.{io, fs, path.Path}
  export brim.compiler.parser.*
}

Function declarations

function_decl = function_modifiers "fn" identifier generic_params?
 param_list return_type? where_clause? function_body ;

function_body = block | "=" expression ;
Modifiers include visibility and behavioral markers such as pure, unsafe, async, inline, cold, extern, test, comptime. Parameter modes:
param_mode = "view" "mut" | "view" | "own" | "move" ;

Type and data declarations

type_decl = item_modifiers "type" type_identifier generic_params? type_decl_body ;
type_decl_body = record_type_body | "=" type_expr ;
data_decl = item_modifiers "data" type_identifier generic_params? data_body ;
data_body = block_open data_variant_list? block_close ;
This enables both record-style and ADT-style modeling.

Traits and impls

trait_decl = item_modifiers "trait" type_identifier generic_params?
 trait_body where_clause? ;

impl_decl = item_modifiers "impl" generic_params?
 impl_target where_clause? impl_body ;
impl_target = type_expr | type_expr "for" type_expr ;

Constants, externs, tests

const_decl = item_modifiers "const" identifier type_annotation? "=" expression ;
extern_block = item_modifiers "extern" abi_string? block_open extern_item_list? block_close ;
test_block = "test" string_literal block ;