Constructs Overview
This section documents the formatting rules for each Ori language construct. All rules follow the core principle: inline if within configured width (default 100), break otherwise.
Construct Categories
Declarations
Top-level items that introduce names:
| Construct | Document |
|---|---|
| Functions | Declarations |
| Constants | Declarations |
| Type definitions | Declarations |
| Traits | Declarations |
| Implementations | Declarations |
| Tests | Declarations |
Expressions
Computations that produce values:
| Construct | Document |
|---|---|
| Function calls | Expressions |
| Method chains | Expressions |
| Conditionals | Expressions |
| Lambdas | Expressions |
| Binary expressions | Expressions |
| Bindings | Expressions |
Patterns
Compiler-recognized constructs with special syntax:
| Construct | Document |
|---|---|
{ } blocks / try | Patterns |
match | Patterns |
recurse | Patterns |
parallel / spawn | Patterns |
timeout / cache | Patterns |
with / in | Patterns |
for loops | Patterns |
nursery | Patterns |
Collections
Aggregate data structures:
| Construct | Document |
|---|---|
| Lists | Collections |
| Maps | Collections |
| Tuples | Collections |
| Struct literals | Collections |
| Ranges | Collections |
Formatting Decision Tree
For any construct, the formatter follows this decision process:
1. Is this an always-stacked construct (blocks, try, match arms)?
YES → Use stacked format
NO → Continue
2. Calculate inline width of the construct
3. Does current_column + inline_width <= max_width?
YES → Use inline format
NO → Use broken format
4. For nested constructs, repeat from step 1
Universal Rules
These rules apply across all constructs:
Spacing
| Context | Rule | Example |
|---|---|---|
| Binary operators | Space around | a + b |
| Arrows | Space around | x -> x + 1 |
| Colons | Space after | x: int |
| Commas | Space after | f(a, b) |
| Parentheses | No inner space | f(x) |
| Brackets | No inner space | [1, 2] |
| Braces | No inner space | { x: 1 } |
| Empty delimiters | No space | [], {}, () |
Trailing Commas
| Format | Rule |
|---|---|
| Single-line | No trailing comma |
| Multi-line | Trailing comma required |
Blank Lines
| Context | Rule |
|---|---|
| After imports | One blank line |
| After constants | One blank line |
| Between functions | One blank line |
| Between trait/impl methods | One blank line |
| Consecutive blank lines | Forbidden |
| Leading/trailing blank lines | Forbidden |