Skip to content

Commit 0359dff

Browse files
committed
improve docs
1 parent dbfe42c commit 0359dff

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-0
lines changed

docs/library/control-flow.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Control Flow
2+
3+
Arx currently supports `if`/`else`, `while`, and two `for` loop styles.
4+
5+
## If / Else
6+
7+
````arx
8+
```
9+
title: If/else example
10+
summary: Branches based on a comparison.
11+
```
12+
fn abs_value(x: i32) -> i32:
13+
```
14+
title: abs_value
15+
summary: Returns absolute value of x.
16+
```
17+
if x < 0:
18+
return 0 - x
19+
else:
20+
return x
21+
````
22+
23+
## While Loop
24+
25+
````arx
26+
```
27+
title: While loop example
28+
summary: Repeats while condition is true.
29+
```
30+
fn count_to_ten() -> i32:
31+
```
32+
title: count_to_ten
33+
summary: Increments value until it reaches ten.
34+
```
35+
var a: i32 = 0
36+
while a < 10:
37+
a = a + 1
38+
return a
39+
````
40+
41+
## For Loop (Range Style)
42+
43+
Range-style loops use the slice-like header:
44+
45+
`for i in (start:end:step):`
46+
47+
````arx
48+
```
49+
title: Range-style for loop
50+
summary: Iterates from start to end with step.
51+
```
52+
fn range_loop(n: i32) -> i32:
53+
```
54+
title: range_loop
55+
summary: Sums values produced by a range loop.
56+
```
57+
var total: i32 = 0
58+
for i in (0:n:1):
59+
total = total + i
60+
return total
61+
````
62+
63+
Tuple-style range headers such as `(0, 5, 1)` are not supported.
64+
65+
## For Loop (Count Style)
66+
67+
Count-style loops follow:
68+
69+
`for var i: type = init; condition; update:`
70+
71+
````arx
72+
```
73+
title: Count-style for loop
74+
summary: Uses initializer, condition, and update expressions.
75+
```
76+
fn count_loop() -> i32:
77+
```
78+
title: count_loop
79+
summary: Sums numbers from 0 to 4.
80+
```
81+
var total: i32 = 0
82+
for var i: i32 = 0; i < 5; i = i + 1:
83+
total = total + i
84+
return total
85+
````
86+
87+
## Return Statements
88+
89+
- `return expr` returns a value from the current function.
90+
- `return none` is used for `none`-returning functions.
91+
92+
## Indentation Rules
93+
94+
- Blocks start after `:`.
95+
- The next logical line must be indented by one level (2 spaces in Arx style).
96+
- Misaligned indentation is treated as a parser error.

docs/library/datatypes.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Data Types
2+
3+
Arx uses explicit type annotations for variables, function parameters, and
4+
optional function return types.
5+
6+
## Type Annotations
7+
8+
- Function parameters must always be typed.
9+
- Function return type is optional. If omitted, current parser default is `f32`.
10+
- Variable declarations can include an explicit type with `var name: type`.
11+
12+
````arx
13+
```
14+
title: Typed function signature
15+
summary: Demonstrates required parameter annotations.
16+
```
17+
fn add(a: i32, b: i32) -> i32:
18+
```
19+
title: add
20+
summary: Returns a + b.
21+
```
22+
return a + b
23+
````
24+
25+
## Built-in Types
26+
27+
| Type | Meaning | Example |
28+
| ----------- | -------------------------- | --------------------- |
29+
| `i8` | 8-bit integer | `var a: i8 = 8` |
30+
| `i16` | 16-bit integer | `var b: i16 = 16` |
31+
| `i32` | 32-bit integer | `var c: i32 = 32` |
32+
| `i64` | 64-bit integer | `var d: i64 = 64` |
33+
| `f16` | 16-bit float | `var x: f16 = 1.5` |
34+
| `f32` | 32-bit float | `var y: f32 = 3.25` |
35+
| `bool` | Boolean | `var ok: bool = true` |
36+
| `none` | No value | `var n: none = none` |
37+
| `str` | String | `var s: str = "hi"` |
38+
| `char` | Character (mapped to `i8`) | `var ch: char = 'A'` |
39+
| `datetime` | Date/time literal | `datetime("...")` |
40+
| `timestamp` | Timestamp literal | `timestamp("...")` |
41+
| `list[T]` | List type | `list[i32]` |
42+
43+
## Strings And Characters
44+
45+
````arx
46+
```
47+
title: String and char types
48+
summary: Declares string and char variables.
49+
```
50+
fn text_demo() -> none:
51+
```
52+
title: text_demo
53+
summary: Uses string and char literals.
54+
```
55+
var greeting: str = "hello"
56+
var initial: char = 'A'
57+
return none
58+
````
59+
60+
## Date And Time Literals
61+
62+
````arx
63+
```
64+
title: Datetime and timestamp literals
65+
summary: Creates date/time values from string literals.
66+
```
67+
fn time_demo() -> none:
68+
```
69+
title: time_demo
70+
summary: Demonstrates datetime/timestamp constructors.
71+
```
72+
var dt: datetime = datetime("2026-03-05T12:30:59")
73+
var ts: timestamp = timestamp("2026-03-05T12:30:59.123456789")
74+
return none
75+
````
76+
77+
## Lists
78+
79+
````arx
80+
```
81+
title: List type example
82+
summary: Declares list variables.
83+
```
84+
fn list_demo() -> none:
85+
```
86+
title: list_demo
87+
summary: Declares populated and empty lists.
88+
```
89+
var ids: list[i32] = [1, 2, 3, 4]
90+
var empty_ids: list[i32] = []
91+
return none
92+
````
93+
94+
Current limitation: list code generation is still limited to empty or
95+
homogeneous integer constant lists.
96+
97+
## Casting
98+
99+
Use the built-in `cast(value, type)` to convert values:
100+
101+
````arx
102+
```
103+
title: Casting example
104+
summary: Converts between numeric and string-compatible forms.
105+
```
106+
fn cast_demo(a: i32) -> str:
107+
```
108+
title: cast_demo
109+
summary: Returns string representation of an integer.
110+
```
111+
return cast(a, str)
112+
````

docs/library/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Start here when you need exact syntax and placement rules.
99

1010
- [Modules](modules.md)
1111
- [Functions](functions.md)
12+
- [Data Types](datatypes.md)
13+
- [Control Flow](control-flow.md)
1214
- [Docstrings](docstrings.md)
1315

1416
## Scope (Current Prototype)
@@ -17,6 +19,8 @@ This reference currently focuses on:
1719

1820
- module structure
1921
- function definitions and calls
22+
- type system and annotations
23+
- control-flow syntax
2024
- docstring placement rules
2125

2226
More feature pages can be added here as the language grows.

mkdocs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ nav:
1111
- Overview: library/index.md
1212
- Modules: library/modules.md
1313
- Functions: library/functions.md
14+
- Data Types: library/datatypes.md
15+
- Control Flow: library/control-flow.md
1416
- Docstrings: library/docstrings.md
1517
- API Docs: api/
1618
- Sponsor: sponsor.md

0 commit comments

Comments
 (0)