format_code/
format_code.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use stackr_rs::*;

fn main() {
    // This is just some ugly code to showcase the formatting.
    // Typically '.' is used as a noop op and helps with formatting.
    let code = r#"
    var 
    stuff 
    .

    1 stuff 
    set .

    stuff
    get 
    .


    : debug "" "" "" print-stack drop ;
    0 begin 1 + dup 2 == if 
            "hello" .  stuff get drop .  break
        end

        dup
        2 == if 
            "hello"
        else
            "world"
            drop
        end
    loop

    "world"
    
    "#;
    let code = Interpreter::<()>::format_code(code, None).unwrap();

    println!("{}", code);
}