Hi Rustillians,

There was some very serious discussion on IRC about writing macros for various esolangs (*obviously* very serious :P ), so I dived in and wrote a simple one for brainfuck.

https://github.com/huonw/brainfuck_macro

Example:

    #![feature(phase)]

    #[phase(syntax)] extern crate brainfuck;

    use std::io;

    fn main() {
        let hello_world = brainfuck!{
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>
---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
        };

        hello_world(&mut io::stdin(), &mut io::stdout());
    }


It's pretty basic (the macro implementation is less than 200 lines), and so probably makes a reasonable example of a procedural macro, especially macros that wish to directly handle the token stream a macro receives (rather than extracting Rust expressions etc. from it).


Huon
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to