Handle binary operators and lifetimes
This commit is contained in:
parent
3f7b59ca2b
commit
0fd174d5f1
@ -669,8 +669,16 @@ impl MacroArgParser {
|
|||||||
if self.buf.is_empty() {
|
if self.buf.is_empty() {
|
||||||
self.lo = lo;
|
self.lo = lo;
|
||||||
self.start_tok = t.clone();
|
self.start_tok = t.clone();
|
||||||
} else if force_space_before(t) {
|
} else {
|
||||||
self.buf.push(' ');
|
let needs_space = match next_space(&self.last_tok) {
|
||||||
|
SpaceState::Ident => ident_like(t),
|
||||||
|
SpaceState::Punctuation => !ident_like(t),
|
||||||
|
SpaceState::Always => true,
|
||||||
|
SpaceState::Never => false,
|
||||||
|
};
|
||||||
|
if force_space_before(t) || needs_space {
|
||||||
|
self.buf.push(' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.buf.push_str(&pprust::token_to_string(t));
|
self.buf.push_str(&pprust::token_to_string(t));
|
||||||
@ -888,9 +896,9 @@ fn force_space_before(tok: &Token) -> bool {
|
|||||||
| Token::RArrow
|
| Token::RArrow
|
||||||
| Token::LArrow
|
| Token::LArrow
|
||||||
| Token::FatArrow
|
| Token::FatArrow
|
||||||
|
| Token::BinOp(_)
|
||||||
| Token::Pound
|
| Token::Pound
|
||||||
| Token::Dollar => true,
|
| Token::Dollar => true,
|
||||||
Token::BinOp(bot) => bot != BinOpToken::Star,
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -907,6 +915,7 @@ fn next_space(tok: &Token) -> SpaceState {
|
|||||||
|
|
||||||
match *tok {
|
match *tok {
|
||||||
Token::Not
|
Token::Not
|
||||||
|
| Token::BinOp(BinOpToken::And)
|
||||||
| Token::Tilde
|
| Token::Tilde
|
||||||
| Token::At
|
| Token::At
|
||||||
| Token::Comma
|
| Token::Comma
|
||||||
@ -916,8 +925,7 @@ fn next_space(tok: &Token) -> SpaceState {
|
|||||||
| Token::DotDotEq
|
| Token::DotDotEq
|
||||||
| Token::DotEq
|
| Token::DotEq
|
||||||
| Token::Question
|
| Token::Question
|
||||||
| Token::Underscore
|
| Token::Underscore => SpaceState::Punctuation,
|
||||||
| Token::BinOp(_) => SpaceState::Punctuation,
|
|
||||||
|
|
||||||
Token::ModSep
|
Token::ModSep
|
||||||
| Token::Pound
|
| Token::Pound
|
||||||
|
@ -10,6 +10,13 @@ macro_rules! m {
|
|||||||
( $( $ i : ident : $ ty : ty , $def : expr , $stb : expr , $ ( $ dstring : tt ) , + ) ; + $ ( ; ) *
|
( $( $ i : ident : $ ty : ty , $def : expr , $stb : expr , $ ( $ dstring : tt ) , + ) ; + $ ( ; ) *
|
||||||
$( $ i : ident : $ ty : ty , $def : expr , $stb : expr , $ ( $ dstring : tt ) , + ) ; + $ ( ; ) *
|
$( $ i : ident : $ ty : ty , $def : expr , $stb : expr , $ ( $ dstring : tt ) , + ) ; + $ ( ; ) *
|
||||||
) => {};
|
) => {};
|
||||||
|
( $foo: tt foo [$ attr : meta] $name: ident ) => {};
|
||||||
|
( $foo: tt [$ attr: meta] $name: ident ) => {};
|
||||||
|
( $foo: tt &'a [$attr : meta] $name: ident ) => {};
|
||||||
|
( $foo: tt foo # [ $attr : meta] $name: ident ) => {};
|
||||||
|
( $foo: tt # [ $attr : meta] $name: ident) => {};
|
||||||
|
( $foo: tt &'a # [ $attr : meta] $name: ident ) => {};
|
||||||
|
( $ x : tt foo bar foo bar foo bar $ y : tt => x*y*z $ z : tt , $ ( $a: tt ) , * ) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! m {
|
macro_rules! m {
|
||||||
|
@ -18,6 +18,13 @@ macro_rules! m {
|
|||||||
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
|
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
|
||||||
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
|
$($i: ident: $ty: ty, $def: expr, $stb: expr, $($dstring: tt),+);+ $(;)*
|
||||||
) => {};
|
) => {};
|
||||||
|
($foo: tt foo[$attr: meta] $name: ident) => {};
|
||||||
|
($foo: tt[$attr: meta] $name: ident) => {};
|
||||||
|
($foo: tt &'a[$attr: meta] $name: ident) => {};
|
||||||
|
($foo: tt foo #[$attr: meta] $name: ident) => {};
|
||||||
|
($foo: tt #[$attr: meta] $name: ident) => {};
|
||||||
|
($foo: tt &'a #[$attr: meta] $name: ident) => {};
|
||||||
|
($x: tt foo bar foo bar foo bar $y: tt => x * y * z $z: tt, $($a: tt),*) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! m {
|
macro_rules! m {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user