Programs, regions & imports
A Faber source file is a program. The compiler reads it from the top: an
optional frontmatter header, an optional module region, then the
declarations, imports, tests, and the entry point that starts it. A file may
also be split by whole-line section markers (+++ toml, +++ faber,
+++ faber test, and stream sections such as +++ text stdout); the
compiler reads only the program section. There is
no hidden wrapper around those declarations and no separate "program"
object to construct.
The words on this page are the ones that give the file its shape. Imports
bring a name in from another file or a library (import from). main is
the ordinary entry; async_main is the one that may await. Tests are
ordinary declarations in the same file — describe names a suite, test
names a case — not a second language and not a second compilation target.
A file that does one thing:
fn salve(string nomen) → string {
let string msg ← "Salve, §!"(nomen)
return msg
}
main {
let string m ← salve("munde")
print m
}faber check accepts that file. faber run prints Salve, munde!.
Tests sit beside the code they exercise:
fn saturate(i32 x) → i32 {
if x ≺ 0 then return 0
if x ≻ 255 then return 255
return x
}
describe "saturate" {
test "clamps low" {
assert saturate(-1) ≡ 0
}
test "clamps high" {
assert saturate(300) ≡ 255
}
}Return to the grammar overview.
Terms#
These are the words you write in this part of the language. Each links to its page. The second column names the grammar rule the word belongs to.
| Term | Grammar rule |
|---|---|
fn | nondum_functio_decl |
import | importa_record |
from | ex_field |
as | ut_field |
all | omnia_field |
from, import | importa_sugar |
public | publica |
as | named_import |
as | wildcard_import |
const | selective_import |
as | import_value_binding |
args, exit | entry_header |
main | incipit_stmt |
async_main | incipiet_stmt |
describe | probandum_decl |
test | proba_stmt |
expect_failure, flaky, todo, bench, skip, repeat, only, only_in, tag, timeout | proba_modifier |
all, teardown, async_teardown, setup, async_setup | praepara_block |
Formal grammar#
The rules for this part of the language are the parser's own definition of it. They are written for models and tools, so this page does not repeat them; the full list is at every production.