Fix syntax bugs
This commit is contained in:
@@ -40,17 +40,17 @@ class Dog : Animal {
|
|||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
override void speak(&self)
|
void speak(&self) override
|
||||||
{
|
{
|
||||||
println!("Woof!");
|
println!("Woof!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `override` keyword supports explicit base class targeting:
|
The `override` keyword supports explicit base class targeting (Required if overriding a nested parent):
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
override(Animal) void speak(&self)
|
void speak(&self) override(Animal)
|
||||||
{
|
{
|
||||||
println!("Woof!");
|
println!("Woof!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
title: Functions
|
title: Functions
|
||||||
description: Function declarations, self parameters, return types, and unsafe functions.
|
description: Function declarations, self parameters, return types, and unsafe functions.
|
||||||
icon: Function
|
icon: SquareFunction
|
||||||
---
|
---
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
@@ -48,7 +48,7 @@ Functions use **Allman brace style** (opening brace on the next line).
|
|||||||
|
|
||||||
### Self Parameter
|
### Self Parameter
|
||||||
|
|
||||||
Methods can take `self`, `&self`, `&mut self`, or `self` with lifetimes:
|
Methods can take `self`, `mut self`, `&self`, `&mut self` additionally with lifetimes:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub void set_value(&mut self, i32 v)
|
pub void set_value(&mut self, i32 v)
|
||||||
|
|||||||
@@ -86,13 +86,13 @@ Macro calls use `!` followed by parentheses, brackets, or braces.
|
|||||||
let add = (a, b) => a + b;
|
let add = (a, b) => a + b;
|
||||||
let result = add(2, 3); // 5
|
let result = add(2, 3); // 5
|
||||||
|
|
||||||
let square = f64 x => x * x;
|
f64 fn() square = (x) => x * x;
|
||||||
```
|
```
|
||||||
|
|
||||||
Closures can have explicit return types:
|
Closures can have explicit return types:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
let transform = i32 x => {
|
let transform = i32 (x) => {
|
||||||
x * 2
|
x * 2
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ pub void external() { }
|
|||||||
// Public to specific path
|
// Public to specific path
|
||||||
pub(crate) void crate_only() { }
|
pub(crate) void crate_only() { }
|
||||||
pub(super) void parent_only() { }
|
pub(super) void parent_only() { }
|
||||||
pub(in my::module) void module_only() { }
|
pub(my::module) void module_only() { }
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ icon: Type
|
|||||||
```mist
|
```mist
|
||||||
i32 // Path type
|
i32 // Path type
|
||||||
str& // Reference type
|
str& // Reference type
|
||||||
&mut i32 // Mutable reference
|
i32 mut& // Mutable reference
|
||||||
&'a i32 // Reference with lifetime
|
i32 'a& // Reference with lifetime
|
||||||
*const i32 // Const pointer
|
i32 unsafe& // Const pointer
|
||||||
*mut i32 // Mutable pointer
|
i32 mut unsafe& // Mutable pointer
|
||||||
(i32, bool) // Tuple type
|
(i32, bool) // Tuple type
|
||||||
fn(i32) -> bool // Function pointer type
|
bool fn(i32) // Function pointer type
|
||||||
Fn(i32) -> bool // Closure trait (Fn)
|
bool Fn(i32) // Closure trait (Fn)
|
||||||
FnMut(i32) -> bool // Closure trait (FnMut)
|
bool FnMut(i32) // Closure trait (FnMut)
|
||||||
FnOnce(i32) -> bool // Closure trait (FnOnce)
|
bool FnOnce(i32) // Closure trait (FnOnce)
|
||||||
dyn Trait // Trait object
|
dyn Trait // Trait object
|
||||||
void // Unit type (maps to Rust's ())
|
void // Unit type (maps to Rust's ())
|
||||||
'lifetime // Lifetime
|
'lifetime // Lifetime
|
||||||
@@ -32,10 +32,10 @@ type_expr = { (void | path_type | tuple_type | dyn_type) ~ (unsafe_ref_type | re
|
|||||||
This means types are written left-to-right naturally:
|
This means types are written left-to-right naturally:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
i32& // &i32
|
i32& // &i32
|
||||||
i32&mut // &mut i32
|
i32 mut& // &mut i32
|
||||||
i32&'a // &'a i32
|
i32 'a& // &'a i32
|
||||||
i32 fn() -> bool // fn(i32) -> bool
|
bool fn(i32) // fn(i32) -> bool
|
||||||
```
|
```
|
||||||
|
|
||||||
### Type Aliases
|
### Type Aliases
|
||||||
|
|||||||
Reference in New Issue
Block a user