Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMulticharacter tokens not parsed correctly #4
Comments
durka
referenced this issue
Aug 14, 2018
Open
Multi-character repetition separators not parseable #8
This comment has been minimized.
This comment has been minimized.
|
The problem here is that we parse (or lower) The two arms parse as (roughly) Ok(MacroRules { name: Ident(x), rules: [Rule { matcher: [Punct(Punct { op: '=', spacing: Alone }), Punct(Punct { op: '>', spacing: Alone })], expansion: TokenStream [Ident { sym: println }, Punct { op: '!', spacing: Alone }, Group { delimiter: Parenthesis, stream: TokenStream [Literal { lit: "Space" }] }, Punct { op: ';', spacing: Alone }] }] })
Ok(MacroRules { name: Ident(x), rules: [Rule { matcher: [Punct(Punct { op: '=', spacing: Joint }), Punct(Punct { op: '>', spacing: Alone })], expansion: TokenStream [Ident { sym: println }, Punct { op: '!', spacing: Alone }, Group { delimiter: Parenthesis, stream: TokenStream [Literal { lit: "No space" }] }, Punct { op: ';', spacing: Alone }] }] })Is case of |
This comment has been minimized.
This comment has been minimized.
|
Macro_rules' concept of tokens is confusing and it's not just a matter of looking at whether the proc macro token is Joint or Alone: macro_rules! x {
// These rules are always equivalent.
(=> >) => { println!("Space"); };
(=>>) => { println!("No space"); };
}
fn main() {
x!(=> >); // "Space"
x!(=>>); // "Space"
}macro_rules! x {
// These rules are *not* equivalent.
(= >>) => { println!("Space"); };
(=>>) => { println!("No space"); };
}
fn main() {
x!(=> >); // "No space"
x!(=>>); // "No space"
}They greedily left-to-right form groups of consecutive punctuation according to which multi-character punctuations are recognized by Rust's grammar, and then whitespace between groups is ignored. (This is a limitation that is fixed in the token API of procedural macros.) So for example |
lukaslueg commentedAug 12, 2018
The two branches are currently seen as identical, even before optimizing. This is not correct.