Skip to content

Language Syntax

Joe Curlee (w4ffl35) edited this page Feb 18, 2026 · 14 revisions

Curlee Syntax (MVP)

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.


1) Top-level structure

A Curlee source file is a sequence of items.

  • Import declarations: import ...;
  • Struct declarations: struct ... { ... }
  • Enum declarations: enum ... { ... }
  • Function declarations: fn ... { ... }
  • Top-level let declarations (optional in MVP)

Notes:

  • import declarations must appear before any fn declarations.

1.5) Imports

Top-level imports only:

import foo;
import foo.bar;
import foo.bar as baz;

Rules:

  • import must 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.

2) Blocks and statements

2.1 Blocks

Blocks use braces:

{
  /* statements */
}

2.2 Statement terminators

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;

3) Functions

3.1 Function header

fn name(param1: Type, param2: Type) -> ReturnType { ... }

Return type is recommended for MVP.

3.2 Contracts (chosen form: bracketed contract block)

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>;
  • result is reserved inside ensures and refers to the returned value.

If a predicate uses constructs outside wiki/Verification-Scope.md, compilation fails with a clear diagnostic.


4) Refinements (where)

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;
}

5) Expressions (MVP)

Expressions include:

  • literals: integers, strings, booleans
  • identifiers
  • member access: value.field
  • unary: !, -
  • binary arithmetic: +, -, *, /
  • comparisons: ==, !=, <, <=, >, >=
  • boolean connectives: &&, ||
  • calls: callee(args...)

5.2) Structs and field access (MVP)

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...) or foo.bar.name(args...)

Note: verification predicates are parsed from expression syntax but are restricted by wiki/Verification-Scope.md.

5.1) Enum construction and pattern matching (MVP)

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::Variant or Enum::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.


6) Minimal grammar sketch (informal)

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 ;

7) Bounded vectors (MVP-run)

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 exceeded
  • vec index out of bounds

Note: capability names must be written without whitespace around . (e.g. cap io.stdout).


7) Keywords (MVP)

Reserved keywords:

  • fn, let, if, else, while, return
  • requires, ensures, where
  • import, as

Planned/reserved for later (do not assign other meanings):

  • unsafe, cap

Clone this wiki locally