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 ...; - 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
- unary:
!,- - binary arithmetic:
+,-,*,/ - comparisons:
==,!=,<,<=,>,>= - boolean connectives:
&&,|| - calls:
callee(args...)
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.
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
| block ;
return_stmt = "return" [ expr ] ;
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 ;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