Improved docs (allman syntax)
This commit is contained in:
@@ -7,17 +7,20 @@ icon: ArrowLeftRight
|
|||||||
### If/Else
|
### If/Else
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
if condition {
|
if condition
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
} else if other_condition {
|
}
|
||||||
|
else if other_condition
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Conditions must be parenthesized: `if (expr) { }` or `if expr_no_struct { }` (struct literals require parentheses).
|
|
||||||
|
|
||||||
Used as an expression:
|
Used as an expression:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
@@ -27,7 +30,8 @@ let x = if true { 1 } else { 2 };
|
|||||||
### While
|
### While
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
while condition {
|
while condition
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -35,11 +39,13 @@ while condition {
|
|||||||
### For
|
### For
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
for pattern in iterator {
|
for pattern in iterator
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0 .. 10 {
|
for i in 0 .. 10
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -47,7 +53,8 @@ for i in 0 .. 10 {
|
|||||||
### C-Style For
|
### C-Style For
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
for (let mut i = 0; i < 10; i++) {
|
for (let mut i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
// body
|
// body
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -55,7 +62,8 @@ for (let mut i = 0; i < 10; i++) {
|
|||||||
### Loop
|
### Loop
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
loop {
|
loop
|
||||||
|
{
|
||||||
// infinite loop
|
// infinite loop
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -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
|
### 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
|
```mist
|
||||||
pub void set_value(&mut self, i32 v)
|
pub void set_value(&mut self, i32 v)
|
||||||
|
|||||||
@@ -12,15 +12,17 @@ T id<T>(T x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generic struct
|
// Generic struct
|
||||||
struct Pair<A, B> {
|
struct Pair<A, B>
|
||||||
|
{
|
||||||
A first,
|
A first,
|
||||||
B second,
|
B second,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic enum
|
// Generic enum
|
||||||
enum Result<T, E> {
|
enum Result<T, E>
|
||||||
Ok(T),
|
{
|
||||||
Err(E),
|
Ok(T);
|
||||||
|
Err(E);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic with trait bounds
|
// Generic with trait bounds
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ match value {
|
|||||||
// Named tuple patterns (newtype)
|
// Named tuple patterns (newtype)
|
||||||
let MyType(value) = my_var;
|
let MyType(value) = my_var;
|
||||||
|
|
||||||
// Wildcard / etc
|
// Wildcard / rest
|
||||||
let _ = get_side_effect();
|
let _ = get_side_effect();
|
||||||
match x {
|
match x {
|
||||||
1 => ...,
|
1 => expr,
|
||||||
.. => ..., // rest / etc
|
.. => expr, // rest / etc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mutable binding in pattern
|
// Mutable binding in pattern
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ icon: Box
|
|||||||
### Structs
|
### Structs
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub struct Point {
|
pub struct Point
|
||||||
|
{
|
||||||
i32 x,
|
i32 x,
|
||||||
i32 y,
|
i32 y,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Generic<T> {
|
pub struct Generic<T>
|
||||||
|
{
|
||||||
T value,
|
T value,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -20,7 +22,8 @@ pub struct Generic<T> {
|
|||||||
Fields can be public or private:
|
Fields can be public or private:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
struct User {
|
struct User
|
||||||
|
{
|
||||||
pub str& name,
|
pub str& name,
|
||||||
i32 age, // private
|
i32 age, // private
|
||||||
}
|
}
|
||||||
@@ -29,12 +32,14 @@ struct User {
|
|||||||
### Enums
|
### Enums
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub enum Option<T> {
|
pub enum Option<T>
|
||||||
|
{
|
||||||
Some(T),
|
Some(T),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Message {
|
pub enum Message
|
||||||
|
{
|
||||||
Quit,
|
Quit,
|
||||||
Move(i32, i32),
|
Move(i32, i32),
|
||||||
Write { str& content, i32 length },
|
Write { str& content, i32 length },
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ icon: Puzzle
|
|||||||
### Traits
|
### Traits
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
pub trait Drawable {
|
pub trait Drawable
|
||||||
|
{
|
||||||
void draw(&self);
|
void draw(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Comparable<T> : Eq {
|
pub trait Comparable<T> : Eq
|
||||||
|
{
|
||||||
i32 cmp(&self, T other);
|
i32 cmp(&self, T other);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -19,7 +21,8 @@ pub trait Comparable<T> : Eq {
|
|||||||
Trait requirements are specified after `:`:
|
Trait requirements are specified after `:`:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
trait MyTrait : SuperTrait + OtherTrait {
|
trait MyTrait : SuperTrait + OtherTrait
|
||||||
|
{
|
||||||
void required_method(&self);
|
void required_method(&self);
|
||||||
void another(&self);
|
void another(&self);
|
||||||
}
|
}
|
||||||
@@ -28,15 +31,18 @@ trait MyTrait : SuperTrait + OtherTrait {
|
|||||||
### Impl Blocks
|
### Impl Blocks
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
impl MyType {
|
impl MyType
|
||||||
|
{
|
||||||
void method(&self) { }
|
void method(&self) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Trait for MyType {
|
impl Trait for MyType
|
||||||
|
{
|
||||||
void method(&self) { }
|
void method(&self) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> GenericTrait<T> for MyType {
|
impl<T> GenericTrait<T> for MyType
|
||||||
|
{
|
||||||
void method(&self, T value) { }
|
void method(&self, T value) { }
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ The semantic checker (`semantics.rs`) performs class field initialization analys
|
|||||||
The primary semantic check ensures all class fields are initialized in the constructor:
|
The primary semantic check ensures all class fields are initialized in the constructor:
|
||||||
|
|
||||||
```mist
|
```mist
|
||||||
class Player {
|
class Player
|
||||||
i32 health,
|
{
|
||||||
str& name,
|
i32 health;
|
||||||
|
str& name;
|
||||||
|
|
||||||
pub constructor(str& name)
|
pub constructor(str& name)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ The transpiler (`transpiler.mist` in `mist_api`) orchestrates the full pipeline.
|
|||||||
|
|
||||||
The `Module` struct represents the file-to-module mapping:
|
The `Module` struct represents the file-to-module mapping:
|
||||||
|
|
||||||
```rust
|
```mist
|
||||||
pub class Module {
|
pub class Module
|
||||||
|
{
|
||||||
pub String name;
|
pub String name;
|
||||||
pub PathBuf path;
|
pub PathBuf path;
|
||||||
pub Vec<Module> children;
|
pub Vec<Module> children;
|
||||||
|
|||||||
Reference in New Issue
Block a user