DanielKeep / tlborm

The Little Book of Rust Macros
880 stars 96 forks source link

Code in Chapter 3 cannot compile #24

Open codeworm96 opened 6 years ago

codeworm96 commented 6 years ago

The compiler doesn't allow the ( a[n]: $sty:ty = $($inits:expr),+ ... $recur:expr ) pattern, as mentioned in https://danielkeep.github.io/tlborm/book/mbe-min-captures-and-expansion-redux.html, only =>, , and ; can follow a expr capture.

BTW, it seems that the MEMORYs in this code block should be MEM_SIZE.

AurevoirXavier commented 6 years ago

Yep, in rust 1.28, the code doesn't work.

It's just a guide. Writing it in that way to make more understandable. We can remove the ... and simply change it to:

// just separate them with ';' or '=>'
[$seq:ident [$ind:ident]: $sty:ty = $($inits:expr),+; $recur:expr]

[$seq:ident [$ind:ident]: $sty:ty = $($inits:expr),+ => $recur:expr]