Skip to content

Commit

Permalink
Support Token![$] for token::Dollar as documented
Browse files Browse the repository at this point in the history
  • Loading branch information
jix committed Jun 26, 2019
1 parent b488739 commit 2ccec11
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fn main() {
None => return,
};

if compiler.minor >= 17 {
println!("cargo:rustc-cfg=syn_can_match_trailing_dollar");
}

if compiler.minor >= 19 {
println!("cargo:rustc-cfg=syn_can_use_thread_id");
}
Expand Down
112 changes: 112 additions & 0 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,118 @@ define_delimiters! {
/// [token module]: token/index.html
// Unfortunate duplication due to a rustdoc bug.
// https://github.com/rust-lang/rust/issues/45939
#[cfg(syn_can_match_trailing_dollar)]
#[macro_export]
#[cfg_attr(rustfmt, rustfmt_skip)]
macro_rules! Token {
(abstract) => { $crate::token::Abstract };
(as) => { $crate::token::As };
(async) => { $crate::token::Async };
(auto) => { $crate::token::Auto };
(become) => { $crate::token::Become };
(box) => { $crate::token::Box };
(break) => { $crate::token::Break };
(const) => { $crate::token::Const };
(continue) => { $crate::token::Continue };
(crate) => { $crate::token::Crate };
(default) => { $crate::token::Default };
(do) => { $crate::token::Do };
(dyn) => { $crate::token::Dyn };
(else) => { $crate::token::Else };
(enum) => { $crate::token::Enum };
(existential) => { $crate::token::Existential };
(extern) => { $crate::token::Extern };
(final) => { $crate::token::Final };
(fn) => { $crate::token::Fn };
(for) => { $crate::token::For };
(if) => { $crate::token::If };
(impl) => { $crate::token::Impl };
(in) => { $crate::token::In };
(let) => { $crate::token::Let };
(loop) => { $crate::token::Loop };
(macro) => { $crate::token::Macro };
(match) => { $crate::token::Match };
(mod) => { $crate::token::Mod };
(move) => { $crate::token::Move };
(mut) => { $crate::token::Mut };
(override) => { $crate::token::Override };
(priv) => { $crate::token::Priv };
(pub) => { $crate::token::Pub };
(ref) => { $crate::token::Ref };
(return) => { $crate::token::Return };
(Self) => { $crate::token::SelfType };
(self) => { $crate::token::SelfValue };
(static) => { $crate::token::Static };
(struct) => { $crate::token::Struct };
(super) => { $crate::token::Super };
(trait) => { $crate::token::Trait };
(try) => { $crate::token::Try };
(type) => { $crate::token::Type };
(typeof) => { $crate::token::Typeof };
(union) => { $crate::token::Union };
(unsafe) => { $crate::token::Unsafe };
(unsized) => { $crate::token::Unsized };
(use) => { $crate::token::Use };
(virtual) => { $crate::token::Virtual };
(where) => { $crate::token::Where };
(while) => { $crate::token::While };
(yield) => { $crate::token::Yield };
(+) => { $crate::token::Add };
(+=) => { $crate::token::AddEq };
(&) => { $crate::token::And };
(&&) => { $crate::token::AndAnd };
(&=) => { $crate::token::AndEq };
(@) => { $crate::token::At };
(!) => { $crate::token::Bang };
(^) => { $crate::token::Caret };
(^=) => { $crate::token::CaretEq };
(:) => { $crate::token::Colon };
(::) => { $crate::token::Colon2 };
(,) => { $crate::token::Comma };
(/) => { $crate::token::Div };
(/=) => { $crate::token::DivEq };
($) => { $crate::token::Dollar };
(.) => { $crate::token::Dot };
(..) => { $crate::token::Dot2 };
(...) => { $crate::token::Dot3 };
(..=) => { $crate::token::DotDotEq };
(=) => { $crate::token::Eq };
(==) => { $crate::token::EqEq };
(>=) => { $crate::token::Ge };
(>) => { $crate::token::Gt };
(<=) => { $crate::token::Le };
(<) => { $crate::token::Lt };
(*=) => { $crate::token::MulEq };
(!=) => { $crate::token::Ne };
(|) => { $crate::token::Or };
(|=) => { $crate::token::OrEq };
(||) => { $crate::token::OrOr };
(#) => { $crate::token::Pound };
(?) => { $crate::token::Question };
(->) => { $crate::token::RArrow };
(<-) => { $crate::token::LArrow };
(%) => { $crate::token::Rem };
(%=) => { $crate::token::RemEq };
(=>) => { $crate::token::FatArrow };
(;) => { $crate::token::Semi };
(<<) => { $crate::token::Shl };
(<<=) => { $crate::token::ShlEq };
(>>) => { $crate::token::Shr };
(>>=) => { $crate::token::ShrEq };
(*) => { $crate::token::Star };
(-) => { $crate::token::Sub };
(-=) => { $crate::token::SubEq };
(~) => { $crate::token::Tilde };
(_) => { $crate::token::Underscore };
}

/// A type-macro that expands to the name of the Rust type representation of a
/// given token.
///
/// See the [token module] documentation for details and examples.
///
/// [token module]: token/index.html
#[cfg(not(syn_can_match_trailing_dollar))]
#[macro_export]
#[cfg_attr(rustfmt, rustfmt_skip)]
macro_rules! Token {
Expand Down
1 change: 1 addition & 0 deletions syn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5757,6 +5757,7 @@
"Div": "/",
"DivEq": "/=",
"Do": "do",
"Dollar": "$",
"Dot": ".",
"Dot2": "..",
"Dot3": "...",
Expand Down

0 comments on commit 2ccec11

Please sign in to comment.