Repository navigation
Language Syntax
This document locks the MVP surface syntax.
Design goals:
- Unambiguous and tooling-friendly (no indentation parsing).
- Highly reliable for LLM generation (explicit delimiters).
- Error recovery-friendly (statement terminators + block delimiters).
- Contracts/refinements are first-class and always either verified (within scope) or rejected (no silent weakening).
Principles are in wiki/Syntax-Principles.md.
A Curlee source file is a sequence of items.
- Import declarations:
import ...; - Struct declarations:
struct ... { ... } - Enum declarations:
enum ... { ... } - Function declarations:
fn ... { ... } - Top-level
letdeclarations (optional in MVP)
Notes:
-
importdeclarations must appear before anyfndeclarations.
Top-level imports only:
import foo;
import foo.bar;
import foo.bar as baz;
Rules:
-
importmust appear at the top level. - The module path is a dotted identifier sequence.
- Optional aliasing is supported via
as <alias>. - A trailing
;is required.
Module resolution rules are specified in Modules and Imports.
Blocks use braces:
{
/* statements */
}
Statements must end with ; where applicable.
This is a deliberate choice to:
- improve parse recovery
- reduce ambiguity for LLMs
Examples:
let x: Int = 1;
print(x);
return;
return x;
fn name(param1: Type, param2: Type) -> ReturnType { ... }
Return type is recommended for MVP.
Contracts attach to a function header via a bracketed block.
fn divide(numerator: Int, denominator: Int) -> Int
[ requires denominator != 0;
ensures result * denominator == numerator; ]
{
return numerator / denominator;
}
Rules:
- Contract block is optional.
- Inside
[...], each clause ends with;. - Supported clauses:
requires <pred>;ensures <pred>;
-
resultis reserved insideensuresand refers to the returned value.
If a predicate uses constructs outside wiki/Verification-Scope.md, compilation fails with a clear diagnostic.
where refines types at bindings and parameters.
Variable refinement:
let x: Int where x > 0 = 5;
Parameter refinement:
fn takes_pos(x: Int where x > 0) -> Int {
return x;
}
Expressions include:
- literals: integers, strings, booleans
- identifiers
- member access:
value.field - unary:
!,- - binary arithmetic:
+,-,*,/ - comparisons:
==,!=,<,<=,>,>= - boolean connectives:
&&,|| - calls:
callee(args...)
Struct declarations and literals:
struct Point {
x: Int;
y: Int;
}
let p: Point = Point{ x: 1, y: 2 };
Field access uses .:
let sum: Int = p.x + p.y;
Rules:
- Struct field declarations end with
;. - Struct literals require named field initializers (
name: expr). - Duplicate field names are rejected with span-precise diagnostics.
- Unknown fields are rejected with span-precise diagnostics.
Calls are intentionally restricted in MVP:
name(args...)- module-qualified:
alias.name(args...)orfoo.bar.name(args...)
Note: verification predicates are parsed from expression syntax but are restricted by wiki/Verification-Scope.md.
Enums support constructor calls via scoped variant names:
enum Maybe {
Some(Int);
None;
}
let x: Maybe = Maybe::Some(1);
let y: Maybe = Maybe::None;
MVP deconstruction uses match with variant-only patterns:
match (x) {
Maybe::Some(n) => {
return n;
}
Maybe::None => {
return 0;
}
}
Pattern rules:
- Arm pattern must be
Enum::VariantorEnum::Variant(binding). - Payload-bearing variants require a binding.
- Variants without payload must not bind a payload.
- Duplicate variant arms are rejected.
- Matches must be exhaustive over declared enum variants.
The match arm body is always a block.
program = { item } ;
item = import_decl | fn_decl | let_decl ";" ;
import_decl = "import" module_path [ "as" IDENT ] ";" ;
module_path = IDENT { "." IDENT } ;
fn_decl = "fn" IDENT "(" [ params ] ")" [ "->" type ]
[ contract_block ] block ;
contract_block = "[" { contract_clause ";" } "]" ;
contract_clause = "requires" pred | "ensures" pred ;
params = param { "," param } ;
param = IDENT ":" type [ "where" pred ] ;
let_decl = "let" IDENT ":" type [ "where" pred ] "=" expr ;
block = "{" { stmt } "}" ;
stmt = let_decl ";"
| expr ";"
| return_stmt ";"
| if_stmt
| while_stmt
| match_stmt
| block ;
return_stmt = "return" [ expr ] ;
match_stmt = "match" "(" expr ")" "{" { match_arm } "}" ;
match_arm = match_pattern "=>" block ;
match_pattern = IDENT "::" IDENT [ "(" IDENT ")" ] ;
pred = expr ;
type = core_type | cap_type | nominal_type ;
core_type = "Int" | "Bool" | "String" | "Unit" ;
cap_type = "cap" capability_name ;
capability_name = IDENT { "." IDENT } ;
nominal_type = IDENT ;Curlee supports a deterministic bounded vector baseline in MVP-run via Vec and stdlib wrappers.
Type form:
let v: Vec = vec.new_int(8);
MVP element support is currently integer-only (Vec<Int> semantics behind Vec).
stdlib v1 API (import std.vec as vec;):
fn new_int(max_len: Int) -> Vec
fn len_int(v: Vec) -> Int
fn push_int(v: Vec, value: Int) -> Unit
fn get_int(v: Vec, index: Int) -> Int
fn set_int(v: Vec, index: Int, value: Int) -> Unit
Deterministic runtime failures:
vec capacity exceededvec index out of bounds
Note: capability names must be written without whitespace around . (e.g. cap io.stdout).
Reserved keywords:
-
fn,let,if,else,while,return -
requires,ensures,where -
import,as
Planned/reserved for later (do not assign other meanings):
-
unsafe,cap