Language Specification
Each specification file covers a major area of the language design, and sections are numbered consistently across documents.
1. Leaf
A high-level introduction to Leaf, its compilation pipeline, assumptions, and built-in types.
- 1.1 Pipeline
- 1.2 Assumptions
- 1.3 Built-in Types
2. Language Semantics
Covers the foundational semantic rules of the language: scoping, mutability, visibility, closures, function types, variance, type inference, annotations, constants, literals, operators, and strings.
§2.0–2.3 — Core
- 2.0 Statement Delimiting and Block Syntax
- 2.0.1 Newlines as Statement Terminators
- 2.0.2 Block Bodies
- 2.1 Scoping
- 2.2 Mutability
- 2.3 Visibility
§2.4–2.9 — Functions
- 2.4 Closures and Nested Functions
- 2.5 Function Types
- 2.6 Variance
- 2.6.1 Subtyping in Leaf
- 2.6.2 Function Type Variance
- 2.6.3 Generic Type Variance
- 2.6.4 Variance Checking Rules
- 2.6.5 Summary
- 2.7 Type Inference
- 2.8 Variable Type Annotations
- 2.9 Return Types
- 2.9.1 Implicit Return
§2.10–2.13 — Values and Operations
- 2.10 Constants
- 2.11 Numeric Types and Literals
- 2.11.1 Integer Types
- 2.11.2 Floating-Point Type
- 2.11.3 No Implicit Numeric Conversion
- 2.12 Operators
- 2.12.1 Compound Assignment
- 2.12.2 Operator Precedence and Associativity
- 2.12.3 The
?Propagation Operator - 2.13 Strings
§2.14–2.17 — Patterns and Syntax
- 2.14 Destructuring, Spread, and Shorthand Syntax
- 2.14.1 Map and Struct Destructuring
- 2.14.2 List Destructuring and Spread
- 2.14.3 Tuple Destructuring
- 2.14.4 Function Parameter Destructuring
- 2.14.5 Shorthand Initialization
- 2.14.6 The
_Discard Binding - 2.14.7 Spread in Collection Literals
- 2.15 Comments
- 2.16 Variadic Functions
- 2.17 Evaluation Order
3. Type System
Describes the advanced type system features: pattern matching, the never type, generators, for loops, and flow control.
- 3.1 Pattern Matching
- 3.2 The
neverType - 3.3 Generators
- 3.4 For Loops
- 3.5 Flow Control
- 3.5.1
if/elseExpressions - 3.5.2
matchExpressions - 3.5.3 Loops
- 3.5.4
returnand Implicit Return
4. Structs, Interfaces, Enums, and Collections
Covers struct declarations, the Self keyword, constructors, generics, interfaces, enums, tuples, collections, and type aliases.
§4.1–4.5 — Core
- 4.1 Structs
- 4.2 The
SelfKeyword - 4.3 Constructors
- 4.4 Generics
- 4.5 Interfaces
§4.6–4.9 — Data Types
- 4.6 Enums
- 4.6.1 Simple Enums
- 4.6.2 Enums with Associated Data
- 4.6.3 Generic Enums
- 4.6.4 Built-in Enums
- 4.7 Tuples
- 4.8 Collections
- 4.8.1 Lists
- 4.8.2 Maps
- 4.8.3 Sets
- 4.8.4 Collection Literals
- 4.9 Type Aliases
5. Source Files
Explains .leaf source files and their rules.
6. Module Resolution
Details how modules are discovered, how imports work (use, @ for external packages, re-exports), path resolution, circular dependency rules, and visibility.
- 6.1 Modules
- 6.2 Project Structure
- 6.3 Import Syntax
- 6.3.1 Project-Local Imports
- 6.3.2 External Package Imports (
@) - 6.3.3 Standard Library Imports (
@std) - 6.3.4 Re-Exports (
pub useandpkg use) - 6.4 Path Resolution Rules
- 6.5 Circular Dependencies
- 6.6 Visibility and Exports
Topic Index
Cross-cutting topics that span multiple spec files:
| Topic | Definition | API/Standard Library | Usage/Patterns |
|---|---|---|---|
| Closures | §2.4 semantics/functions.md | — | §2.5 Function Types |
| Collections | §4.8 structs/data-types.md | stdlib/types.md | §2.14 Destructuring |
| Enums | §4.6 structs/data-types.md | stdlib/types.md | §3.1 Pattern Matching |
| Generics | §4.4 structs/core.md | — | §2.6 Variance |
| Interfaces | §4.5 structs/core.md | stdlib/interfaces.md | Conformance |
| Iterators | — | stdlib/interfaces.md | §3.4 For Loops |
| Numeric Types | §2.11 semantics/values.md | stdlib/functions.md | §2.12 Operators |
| Tuples | §4.7 structs/data-types.md | stdlib/types.md | §2.14.3 Destructuring |