Macro obfuscate_integer::cai[][src]

macro_rules! cai {
    (@ expr_block($($ex : tt) +) => { $($b1 : tt) * } else { $($b2 : tt) * }
 $($tail : tt) *) => { ... };
    (@ expr_block($($ex : tt) +) => { $($b1 : tt) * } $($tail : tt) *) => { ... };
    ({ $($b1 : tt) * } $($tail : tt) *) => { ... };
    (@ split_exp_block($($ex : tt) +) => { $($b : tt) * } $($tail : tt) *) => { ... };
    (@ split_exp_block($($ex : tt) +) => $t : tt $($tail : tt) *) => { ... };
    (if $t : tt $($tail : tt) *) => { ... };
    (while $t : tt $($tail : tt) *) => { ... };
    (break { $($b : tt) * } $($tail : tt) *) => { ... };
    (loop { $($b : tt) * } $($tail : tt) *) => { ... };
    (for $t : tt $($tail : tt) *) => { ... };
    ({ $($b : tt) * } $($tail : tt) *) => { ... };
    ($id : ident ~ $ex : expr ; $($tail : tt) *) => { ... };
    ($($id : ident) + $(: $type : ty) ? : = $ex : expr ; $($tail : tt) *) => { ... };
    ($st : stmt ; $($tail : tt) *) => { ... };
    ($ex : expr) => { ... };
    () => { ... };
}
Expand description

Custom Initialize and Assign statement with macro cai!

Example

#[macro_use] // if you want to import the macro
extern crate obfuscate_integer;
use obfuscate_integer::custom_ops::*;
fn main(){
    cai!{
        let _a=1;               // a normal statement
        let mut a:i32 :=0;      // Custom Initialize (let mut a:i32 =CustomInitialize::custom_initialize())
        a+=1;                   // stmt
        println!("{}: cai! works directly in the environment of macro",a);
        for i in 0i32..1{
            let j:i32 :=3;
            println!("{}: cai! also works in for-loop",j-a+i)
        }
        a~2;                    // Custom Assign (bind to `~`)
        if a==2{
            let j:i32 :=1;
            println!("{}: cai! also works in if statement",a+j)
        }
        a.custom_assign(6i32);  // expr with no ending semicolon
        if a==1i32{
        }else{
            let j:i32 :=2;
            println!("{}: cai! also works in if statement with `else` clause, empty block, etc.",a-j)
        }
        while a!=1{
            a:=1;               // := could be used without let clause.
            println!("5: cai! also works in while statement.")
        }
        loop{
            println!("{}: cai! also works in loop statement.",a+5);
            break {
                let b:i32 := 7 ;
                println!("{}: cai! also works in loop statement.",b) ;
                b
            }
        }
        println!("{}: as a special remainder, cai does not works in closure nor blocks in a statement that is not mentioned above.",a+7)
    }
}