Improved docs (allman syntax)

This commit is contained in:
2026-07-03 22:21:33 +02:00
parent ddf3efdf6e
commit 581390933d
8 changed files with 57 additions and 38 deletions
+18 -10
View File
@@ -7,17 +7,20 @@ icon: ArrowLeftRight
### If/Else
```mist
if condition {
if condition
{
// body
} else if other_condition {
}
else if other_condition
{
// body
} else {
}
else
{
// body
}
```
Conditions must be parenthesized: `if (expr) { }` or `if expr_no_struct { }` (struct literals require parentheses).
Used as an expression:
```mist
@@ -27,7 +30,8 @@ let x = if true { 1 } else { 2 };
### While
```mist
while condition {
while condition
{
// body
}
```
@@ -35,11 +39,13 @@ while condition {
### For
```mist
for pattern in iterator {
for pattern in iterator
{
// body
}
for i in 0 .. 10 {
for i in 0 .. 10
{
// body
}
```
@@ -47,7 +53,8 @@ for i in 0 .. 10 {
### C-Style For
```mist
for (let mut i = 0; i < 10; i++) {
for (let mut i = 0; i < 10; i++)
{
// body
}
```
@@ -55,7 +62,8 @@ for (let mut i = 0; i < 10; i++) {
### Loop
```mist
loop {
loop
{
// infinite loop
}
```
+1 -5
View File
@@ -42,13 +42,9 @@ unsafe i32 dangerous()
}
```
Function syntax: `[pub] [void | <type>] <name>[<generics>](<params>) [override] { <body> }`
Functions use **Allman brace style** (opening brace on the next line).
### Self Parameter
Methods can take `self`, `mut self`, `&self`, `&mut self` additionally with lifetimes:
Methods can take `self`, `mut self`, `&self`, `&mut self`, and `&'a self` / `&'a mut self` with lifetimes:
```mist
pub void set_value(&mut self, i32 v)
+6 -4
View File
@@ -12,15 +12,17 @@ T id<T>(T x)
}
// Generic struct
struct Pair<A, B> {
struct Pair<A, B>
{
A first,
B second,
}
// Generic enum
enum Result<T, E> {
Ok(T),
Err(E),
enum Result<T, E>
{
Ok(T);
Err(E);
}
// Generic with trait bounds
+3 -3
View File
@@ -25,11 +25,11 @@ match value {
// Named tuple patterns (newtype)
let MyType(value) = my_var;
// Wildcard / etc
// Wildcard / rest
let _ = get_side_effect();
match x {
1 => ...,
.. => ..., // rest / etc
1 => expr,
.. => expr, // rest / etc
}
// Mutable binding in pattern
+10 -5
View File
@@ -7,12 +7,14 @@ icon: Box
### Structs
```mist
pub struct Point {
pub struct Point
{
i32 x,
i32 y,
}
pub struct Generic<T> {
pub struct Generic<T>
{
T value,
}
```
@@ -20,7 +22,8 @@ pub struct Generic<T> {
Fields can be public or private:
```mist
struct User {
struct User
{
pub str& name,
i32 age, // private
}
@@ -29,12 +32,14 @@ struct User {
### Enums
```mist
pub enum Option<T> {
pub enum Option<T>
{
Some(T),
None,
}
pub enum Message {
pub enum Message
{
Quit,
Move(i32, i32),
Write { str& content, i32 length },
+12 -6
View File
@@ -7,11 +7,13 @@ icon: Puzzle
### Traits
```mist
pub trait Drawable {
pub trait Drawable
{
void draw(&self);
}
pub trait Comparable<T> : Eq {
pub trait Comparable<T> : Eq
{
i32 cmp(&self, T other);
}
```
@@ -19,7 +21,8 @@ pub trait Comparable<T> : Eq {
Trait requirements are specified after `:`:
```mist
trait MyTrait : SuperTrait + OtherTrait {
trait MyTrait : SuperTrait + OtherTrait
{
void required_method(&self);
void another(&self);
}
@@ -28,15 +31,18 @@ trait MyTrait : SuperTrait + OtherTrait {
### Impl Blocks
```mist
impl MyType {
impl MyType
{
void method(&self) { }
}
impl Trait for MyType {
impl Trait for MyType
{
void method(&self) { }
}
impl<T> GenericTrait<T> for MyType {
impl<T> GenericTrait<T> for MyType
{
void method(&self, T value) { }
}
```