Skip to Content
Cloth
DocumentationReferenceLanguageOverview

Language Overview

This section describes the syntax and semantics of the Cloth language. Each page covers a single category of construct — what the syntax looks like, what it means, and how it relates to the rest of the language.

Pages in this section

  • Modules and Imports — How source files are organized into modules and how identifiers are brought into scope.
  • Classes and Structs — Reference and value type declarations, including primary parameters, constructors, destructors, fields, and inheritance.
  • Interfaces, Traits, and Enums — Abstract contracts, attribute-style traits, and enumerated types.
  • Functions and Fragments — Function and fragment declarations, parameters, return types, modifiers, and lambdas.
  • Variables and Visibility — Variable bindings, constants, and the access modifiers public, private, and internal.
  • Control Flow — Conditionals, loops, switches, and the early-exit statements.
  • Operators — Every operator the lexer recognizes, grouped by category.
  • Memory and Errors — The hierarchical ownership model, deterministic destruction, and the error-handling primitives maybe, throw, guard, defer, and ??.
  • Annotations@Extern for foreign-function bindings, the trait annotations (#Override, #Implementation, #Deprecated), and the metakeywords (#SIZE, #ALIGN, etc.).

Common conventions

A few conventions are uniform across the language and worth stating once:

  • Files end in .co. Every Cloth source file uses this extension.
  • Every file begins with a module declaration. The module path mirrors the file’s location relative to the project’s source root.
  • Statements end with a semicolon. This includes top-level declarations such as module, import, and field declarations, as well as ordinary statements inside method bodies.
  • All code lives inside a class. Cloth has no free-standing functions at file scope. Top-level code goes inside a class declaration; the class named after the file (or, if a file declares only one class, the only class in that file) defines the file’s contents.
  • Cloth is case-sensitive. Identifiers, keywords, and type names all distinguish case.