Skip to content

Language Syntax

Joe Curlee (w4ffl35) edited this page Feb 4, 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 ...;
  • 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
  • unary: !, -
  • binary arithmetic: +, -, *, /
  • comparisons: ==, !=, <, <=, >, >=
  • boolean connectives: &&, ||
  • calls: callee(args...)

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.


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

return_stmt    = "return" [ expr ] ;

pred           = expr ;

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