Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1 | //! Discrete tokens that can be parsed out by synom. |
| 2 | //! |
| 3 | //! This module contains a number of useful tokens like `+=` and `/` along with |
| 4 | //! keywords like `crate` and such. These structures are used to track the spans |
| 5 | //! of these tokens and all implment the `ToTokens` and `Synom` traits when the |
| 6 | //! corresponding feature is activated. |
| 7 | |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 8 | use proc_macro2::Span; |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 9 | |
| 10 | macro_rules! tokens { |
| 11 | ( |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 12 | punct: { |
| 13 | $($punct:tt pub struct $punct_name:ident/$len:tt #[$punct_doc:meta])* |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 14 | } |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 15 | delimiter: { |
| 16 | $($delimiter:tt pub struct $delimiter_name:ident #[$delimiter_doc:meta])* |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 17 | } |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 18 | keyword: { |
| 19 | $($keyword:tt pub struct $keyword_name:ident #[$keyword_doc:meta])* |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 20 | } |
| 21 | ) => ( |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 22 | $(token_punct! { #[$punct_doc] $punct pub struct $punct_name/$len })* |
| 23 | $(token_delimiter! { #[$delimiter_doc] $delimiter pub struct $delimiter_name })* |
| 24 | $(token_keyword! { #[$keyword_doc] $keyword pub struct $keyword_name })* |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 25 | ) |
| 26 | } |
| 27 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 28 | macro_rules! token_punct { |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 29 | (#[$doc:meta] $s:tt pub struct $name:ident/$len:tt) => { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 30 | #[cfg_attr(feature = "clone-impls", derive(Copy, Clone))] |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 31 | #[derive(Default)] |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 32 | #[$doc] |
| 33 | pub struct $name(pub [Span; $len]); |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 34 | |
David Tolnay | 0bdb055 | 2017-12-27 21:31:51 -0500 | [diff] [blame] | 35 | impl $name { |
| 36 | pub fn new(span: Span) -> Self { |
| 37 | $name([span; $len]) |
| 38 | } |
| 39 | } |
| 40 | |
Nika Layzell | d73a365 | 2017-10-24 08:57:05 -0400 | [diff] [blame] | 41 | #[cfg(feature = "extra-traits")] |
| 42 | impl ::std::fmt::Debug for $name { |
| 43 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 44 | f.write_str(stringify!($name)) |
Nika Layzell | d73a365 | 2017-10-24 08:57:05 -0400 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 48 | #[cfg(feature = "extra-traits")] |
| 49 | impl ::std::cmp::Eq for $name {} |
| 50 | |
| 51 | #[cfg(feature = "extra-traits")] |
| 52 | impl ::std::cmp::PartialEq for $name { |
| 53 | fn eq(&self, _other: &$name) -> bool { |
| 54 | true |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | #[cfg(feature = "extra-traits")] |
| 59 | impl ::std::hash::Hash for $name { |
| 60 | fn hash<H>(&self, _state: &mut H) |
| 61 | where H: ::std::hash::Hasher |
| 62 | {} |
| 63 | } |
| 64 | |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 65 | #[cfg(feature = "printing")] |
| 66 | impl ::quote::ToTokens for $name { |
| 67 | fn to_tokens(&self, tokens: &mut ::quote::Tokens) { |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 68 | printing::punct($s, &self.0, tokens); |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | #[cfg(feature = "parsing")] |
| 73 | impl ::Synom for $name { |
David Tolnay | 203557a | 2017-12-27 23:59:33 -0500 | [diff] [blame] | 74 | fn parse(tokens: $crate::synom::Cursor) -> $crate::synom::PResult<$name> { |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 75 | parsing::punct($s, tokens, $name) |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 76 | } |
Sergio Benitez | 5680d6a | 2017-12-29 11:20:29 -0800 | [diff] [blame] | 77 | |
| 78 | fn description() -> Option<&'static str> { |
| 79 | Some(concat!("`", $s, "`")) |
| 80 | } |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 85 | macro_rules! token_keyword { |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 86 | (#[$doc:meta] $s:tt pub struct $name:ident) => { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 87 | #[cfg_attr(feature = "clone-impls", derive(Copy, Clone))] |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 88 | #[derive(Default)] |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 89 | #[$doc] |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 90 | pub struct $name(pub Span); |
| 91 | |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 92 | #[cfg(feature = "extra-traits")] |
| 93 | impl ::std::fmt::Debug for $name { |
| 94 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { |
| 95 | f.write_str(stringify!($name)) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | #[cfg(feature = "extra-traits")] |
| 100 | impl ::std::cmp::Eq for $name {} |
| 101 | |
| 102 | #[cfg(feature = "extra-traits")] |
| 103 | impl ::std::cmp::PartialEq for $name { |
| 104 | fn eq(&self, _other: &$name) -> bool { |
| 105 | true |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | #[cfg(feature = "extra-traits")] |
| 110 | impl ::std::hash::Hash for $name { |
| 111 | fn hash<H>(&self, _state: &mut H) |
| 112 | where H: ::std::hash::Hasher |
| 113 | {} |
| 114 | } |
| 115 | |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 116 | #[cfg(feature = "printing")] |
| 117 | impl ::quote::ToTokens for $name { |
| 118 | fn to_tokens(&self, tokens: &mut ::quote::Tokens) { |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 119 | printing::keyword($s, &self.0, tokens); |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | #[cfg(feature = "parsing")] |
| 124 | impl ::Synom for $name { |
David Tolnay | 203557a | 2017-12-27 23:59:33 -0500 | [diff] [blame] | 125 | fn parse(tokens: $crate::synom::Cursor) -> $crate::synom::PResult<$name> { |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 126 | parsing::keyword($s, tokens, $name) |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 132 | macro_rules! token_delimiter { |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 133 | (#[$doc:meta] $s:tt pub struct $name:ident) => { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 134 | #[cfg_attr(feature = "clone-impls", derive(Copy, Clone))] |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 135 | #[derive(Default)] |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 136 | #[$doc] |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 137 | pub struct $name(pub Span); |
| 138 | |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 139 | #[cfg(feature = "extra-traits")] |
| 140 | impl ::std::fmt::Debug for $name { |
| 141 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { |
| 142 | f.write_str(stringify!($name)) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | #[cfg(feature = "extra-traits")] |
| 147 | impl ::std::cmp::Eq for $name {} |
| 148 | |
| 149 | #[cfg(feature = "extra-traits")] |
| 150 | impl ::std::cmp::PartialEq for $name { |
| 151 | fn eq(&self, _other: &$name) -> bool { |
| 152 | true |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | #[cfg(feature = "extra-traits")] |
| 157 | impl ::std::hash::Hash for $name { |
| 158 | fn hash<H>(&self, _state: &mut H) |
| 159 | where H: ::std::hash::Hasher |
| 160 | {} |
| 161 | } |
| 162 | |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 163 | impl $name { |
| 164 | #[cfg(feature = "printing")] |
| 165 | pub fn surround<F>(&self, |
| 166 | tokens: &mut ::quote::Tokens, |
| 167 | f: F) |
| 168 | where F: FnOnce(&mut ::quote::Tokens) |
| 169 | { |
| 170 | printing::delim($s, &self.0, tokens, f); |
| 171 | } |
| 172 | |
| 173 | #[cfg(feature = "parsing")] |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 174 | pub fn parse<F, R>(tokens: $crate::synom::Cursor, f: F) -> $crate::synom::PResult<($name, R)> |
David Tolnay | 203557a | 2017-12-27 23:59:33 -0500 | [diff] [blame] | 175 | where F: FnOnce($crate::synom::Cursor) -> $crate::synom::PResult<R> |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 176 | { |
| 177 | parsing::delim($s, tokens, $name, f) |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | tokens! { |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 184 | punct: { |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 185 | "+" pub struct Add/1 /// `+` |
| 186 | "+=" pub struct AddEq/2 /// `+=` |
| 187 | "&" pub struct And/1 /// `&` |
| 188 | "&&" pub struct AndAnd/2 /// `&&` |
| 189 | "&=" pub struct AndEq/2 /// `&=` |
| 190 | "@" pub struct At/1 /// `@` |
| 191 | "!" pub struct Bang/1 /// `!` |
| 192 | "^" pub struct Caret/1 /// `^` |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 193 | "^=" pub struct CaretEq/2 /// `^=` |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 194 | ":" pub struct Colon/1 /// `:` |
| 195 | "::" pub struct Colon2/2 /// `::` |
| 196 | "," pub struct Comma/1 /// `,` |
| 197 | "/" pub struct Div/1 /// `/` |
| 198 | "/=" pub struct DivEq/2 /// `/=` |
| 199 | "." pub struct Dot/1 /// `.` |
| 200 | ".." pub struct Dot2/2 /// `..` |
| 201 | "..." pub struct Dot3/3 /// `...` |
| 202 | "..=" pub struct DotDotEq/3 /// `..=` |
| 203 | "=" pub struct Eq/1 /// `=` |
| 204 | "==" pub struct EqEq/2 /// `==` |
| 205 | ">=" pub struct Ge/2 /// `>=` |
| 206 | ">" pub struct Gt/1 /// `>` |
| 207 | "<=" pub struct Le/2 /// `<=` |
| 208 | "<" pub struct Lt/1 /// `<` |
| 209 | "*=" pub struct MulEq/2 /// `*=` |
| 210 | "!=" pub struct Ne/2 /// `!=` |
| 211 | "|" pub struct Or/1 /// `|` |
| 212 | "|=" pub struct OrEq/2 /// `|=` |
| 213 | "||" pub struct OrOr/2 /// `||` |
| 214 | "#" pub struct Pound/1 /// `#` |
| 215 | "?" pub struct Question/1 /// `?` |
| 216 | "->" pub struct RArrow/2 /// `->` |
| 217 | "<-" pub struct LArrow/2 /// `<-` |
| 218 | "%" pub struct Rem/1 /// `%` |
| 219 | "%=" pub struct RemEq/2 /// `%=` |
| 220 | "=>" pub struct Rocket/2 /// `=>` |
| 221 | ";" pub struct Semi/1 /// `;` |
| 222 | "<<" pub struct Shl/2 /// `<<` |
| 223 | "<<=" pub struct ShlEq/3 /// `<<=` |
| 224 | ">>" pub struct Shr/2 /// `>>` |
| 225 | ">>=" pub struct ShrEq/3 /// `>>=` |
| 226 | "*" pub struct Star/1 /// `*` |
| 227 | "-" pub struct Sub/1 /// `-` |
| 228 | "-=" pub struct SubEq/2 /// `-=` |
| 229 | "_" pub struct Underscore/1 /// `_` |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 230 | } |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 231 | delimiter: { |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 232 | "{" pub struct Brace /// `{...}` |
| 233 | "[" pub struct Bracket /// `[...]` |
| 234 | "(" pub struct Paren /// `(...)` |
| 235 | " " pub struct Group /// None-delimited group |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 236 | } |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 237 | keyword: { |
David Tolnay | 5a20f63 | 2017-12-26 22:11:28 -0500 | [diff] [blame] | 238 | "as" pub struct As /// `as` |
| 239 | "auto" pub struct Auto /// `auto` |
| 240 | "box" pub struct Box /// `box` |
| 241 | "break" pub struct Break /// `break` |
| 242 | "Self" pub struct CapSelf /// `Self` |
| 243 | "catch" pub struct Catch /// `catch` |
| 244 | "const" pub struct Const /// `const` |
| 245 | "continue" pub struct Continue /// `continue` |
| 246 | "crate" pub struct Crate /// `crate` |
| 247 | "default" pub struct Default /// `default` |
| 248 | "do" pub struct Do /// `do` |
| 249 | "dyn" pub struct Dyn /// `dyn` |
| 250 | "else" pub struct Else /// `else` |
| 251 | "enum" pub struct Enum /// `enum` |
| 252 | "extern" pub struct Extern /// `extern` |
| 253 | "fn" pub struct Fn /// `fn` |
| 254 | "for" pub struct For /// `for` |
| 255 | "if" pub struct If /// `if` |
| 256 | "impl" pub struct Impl /// `impl` |
| 257 | "in" pub struct In /// `in` |
| 258 | "let" pub struct Let /// `let` |
| 259 | "loop" pub struct Loop /// `loop` |
| 260 | "macro" pub struct Macro /// `macro` |
| 261 | "match" pub struct Match /// `match` |
| 262 | "mod" pub struct Mod /// `mod` |
| 263 | "move" pub struct Move /// `move` |
| 264 | "mut" pub struct Mut /// `mut` |
| 265 | "pub" pub struct Pub /// `pub` |
| 266 | "ref" pub struct Ref /// `ref` |
| 267 | "return" pub struct Return /// `return` |
| 268 | "self" pub struct Self_ /// `self` |
| 269 | "static" pub struct Static /// `static` |
| 270 | "struct" pub struct Struct /// `struct` |
| 271 | "super" pub struct Super /// `super` |
| 272 | "trait" pub struct Trait /// `trait` |
| 273 | "type" pub struct Type /// `type` |
| 274 | "union" pub struct Union /// `union` |
| 275 | "unsafe" pub struct Unsafe /// `unsafe` |
| 276 | "use" pub struct Use /// `use` |
| 277 | "where" pub struct Where /// `where` |
| 278 | "while" pub struct While /// `while` |
| 279 | "yield" pub struct Yield /// `yield` |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 283 | // Unfortunate duplication due to a rustdoc bug. |
| 284 | // https://github.com/rust-lang/rust/issues/45939 |
| 285 | #[macro_export] |
| 286 | macro_rules! Token { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 287 | (+) => { $crate::token::Add }; |
| 288 | (+=) => { $crate::token::AddEq }; |
| 289 | (&) => { $crate::token::And }; |
| 290 | (&&) => { $crate::token::AndAnd }; |
| 291 | (&=) => { $crate::token::AndEq }; |
| 292 | (@) => { $crate::token::At }; |
| 293 | (!) => { $crate::token::Bang }; |
| 294 | (^) => { $crate::token::Caret }; |
| 295 | (^=) => { $crate::token::CaretEq }; |
| 296 | (:) => { $crate::token::Colon }; |
| 297 | (::) => { $crate::token::Colon2 }; |
| 298 | (,) => { $crate::token::Comma }; |
| 299 | (/) => { $crate::token::Div }; |
| 300 | (/=) => { $crate::token::DivEq }; |
| 301 | (.) => { $crate::token::Dot }; |
| 302 | (..) => { $crate::token::Dot2 }; |
| 303 | (...) => { $crate::token::Dot3 }; |
| 304 | (..=) => { $crate::token::DotDotEq }; |
| 305 | (=) => { $crate::token::Eq }; |
| 306 | (==) => { $crate::token::EqEq }; |
| 307 | (>=) => { $crate::token::Ge }; |
| 308 | (>) => { $crate::token::Gt }; |
| 309 | (<=) => { $crate::token::Le }; |
| 310 | (<) => { $crate::token::Lt }; |
| 311 | (*=) => { $crate::token::MulEq }; |
| 312 | (!=) => { $crate::token::Ne }; |
| 313 | (|) => { $crate::token::Or }; |
| 314 | (|=) => { $crate::token::OrEq }; |
| 315 | (||) => { $crate::token::OrOr }; |
| 316 | (#) => { $crate::token::Pound }; |
| 317 | (?) => { $crate::token::Question }; |
| 318 | (->) => { $crate::token::RArrow }; |
| 319 | (<-) => { $crate::token::LArrow }; |
| 320 | (%) => { $crate::token::Rem }; |
| 321 | (%=) => { $crate::token::RemEq }; |
| 322 | (=>) => { $crate::token::Rocket }; |
| 323 | (;) => { $crate::token::Semi }; |
| 324 | (<<) => { $crate::token::Shl }; |
| 325 | (<<=) => { $crate::token::ShlEq }; |
| 326 | (>>) => { $crate::token::Shr }; |
| 327 | (>>=) => { $crate::token::ShrEq }; |
| 328 | (*) => { $crate::token::Star }; |
| 329 | (-) => { $crate::token::Sub }; |
| 330 | (-=) => { $crate::token::SubEq }; |
| 331 | (_) => { $crate::token::Underscore }; |
| 332 | (as) => { $crate::token::As }; |
| 333 | (auto) => { $crate::token::Auto }; |
| 334 | (box) => { $crate::token::Box }; |
| 335 | (break) => { $crate::token::Break }; |
| 336 | (Self) => { $crate::token::CapSelf }; |
| 337 | (catch) => { $crate::token::Catch }; |
| 338 | (const) => { $crate::token::Const }; |
| 339 | (continue) => { $crate::token::Continue }; |
| 340 | (crate) => { $crate::token::Crate }; |
| 341 | (default) => { $crate::token::Default }; |
| 342 | (do) => { $crate::token::Do }; |
| 343 | (dyn) => { $crate::token::Dyn }; |
| 344 | (else) => { $crate::token::Else }; |
| 345 | (enum) => { $crate::token::Enum }; |
| 346 | (extern) => { $crate::token::Extern }; |
| 347 | (fn) => { $crate::token::Fn }; |
| 348 | (for) => { $crate::token::For }; |
| 349 | (if) => { $crate::token::If }; |
| 350 | (impl) => { $crate::token::Impl }; |
| 351 | (in) => { $crate::token::In }; |
| 352 | (let) => { $crate::token::Let }; |
| 353 | (loop) => { $crate::token::Loop }; |
| 354 | (macro) => { $crate::token::Macro }; |
| 355 | (match) => { $crate::token::Match }; |
| 356 | (mod) => { $crate::token::Mod }; |
| 357 | (move) => { $crate::token::Move }; |
| 358 | (mut) => { $crate::token::Mut }; |
| 359 | (pub) => { $crate::token::Pub }; |
| 360 | (ref) => { $crate::token::Ref }; |
| 361 | (return) => { $crate::token::Return }; |
| 362 | (self) => { $crate::token::Self_ }; |
| 363 | (static) => { $crate::token::Static }; |
| 364 | (struct) => { $crate::token::Struct }; |
| 365 | (super) => { $crate::token::Super }; |
| 366 | (trait) => { $crate::token::Trait }; |
| 367 | (type) => { $crate::token::Type }; |
| 368 | (union) => { $crate::token::Union }; |
| 369 | (unsafe) => { $crate::token::Unsafe }; |
| 370 | (use) => { $crate::token::Use }; |
| 371 | (where) => { $crate::token::Where }; |
| 372 | (while) => { $crate::token::While }; |
| 373 | (yield) => { $crate::token::Yield }; |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 374 | } |
| 375 | |
David Tolnay | 0fbe328 | 2017-12-26 21:46:16 -0500 | [diff] [blame] | 376 | #[cfg(feature = "parsing")] |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 377 | #[macro_export] |
| 378 | macro_rules! punct { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 379 | ($i:expr, +) => { call!($i, <$crate::token::Add as $crate::synom::Synom>::parse) }; |
| 380 | ($i:expr, +=) => { call!($i, <$crate::token::AddEq as $crate::synom::Synom>::parse) }; |
| 381 | ($i:expr, &) => { call!($i, <$crate::token::And as $crate::synom::Synom>::parse) }; |
| 382 | ($i:expr, &&) => { call!($i, <$crate::token::AndAnd as $crate::synom::Synom>::parse) }; |
| 383 | ($i:expr, &=) => { call!($i, <$crate::token::AndEq as $crate::synom::Synom>::parse) }; |
| 384 | ($i:expr, @) => { call!($i, <$crate::token::At as $crate::synom::Synom>::parse) }; |
| 385 | ($i:expr, !) => { call!($i, <$crate::token::Bang as $crate::synom::Synom>::parse) }; |
| 386 | ($i:expr, ^) => { call!($i, <$crate::token::Caret as $crate::synom::Synom>::parse) }; |
| 387 | ($i:expr, ^=) => { call!($i, <$crate::token::CaretEq as $crate::synom::Synom>::parse) }; |
| 388 | ($i:expr, :) => { call!($i, <$crate::token::Colon as $crate::synom::Synom>::parse) }; |
| 389 | ($i:expr, ::) => { call!($i, <$crate::token::Colon2 as $crate::synom::Synom>::parse) }; |
| 390 | ($i:expr, ,) => { call!($i, <$crate::token::Comma as $crate::synom::Synom>::parse) }; |
| 391 | ($i:expr, /) => { call!($i, <$crate::token::Div as $crate::synom::Synom>::parse) }; |
| 392 | ($i:expr, /=) => { call!($i, <$crate::token::DivEq as $crate::synom::Synom>::parse) }; |
| 393 | ($i:expr, .) => { call!($i, <$crate::token::Dot as $crate::synom::Synom>::parse) }; |
| 394 | ($i:expr, ..) => { call!($i, <$crate::token::Dot2 as $crate::synom::Synom>::parse) }; |
| 395 | ($i:expr, ...) => { call!($i, <$crate::token::Dot3 as $crate::synom::Synom>::parse) }; |
| 396 | ($i:expr, ..=) => { call!($i, <$crate::token::DotDotEq as $crate::synom::Synom>::parse) }; |
| 397 | ($i:expr, =) => { call!($i, <$crate::token::Eq as $crate::synom::Synom>::parse) }; |
| 398 | ($i:expr, ==) => { call!($i, <$crate::token::EqEq as $crate::synom::Synom>::parse) }; |
| 399 | ($i:expr, >=) => { call!($i, <$crate::token::Ge as $crate::synom::Synom>::parse) }; |
| 400 | ($i:expr, >) => { call!($i, <$crate::token::Gt as $crate::synom::Synom>::parse) }; |
| 401 | ($i:expr, <=) => { call!($i, <$crate::token::Le as $crate::synom::Synom>::parse) }; |
| 402 | ($i:expr, <) => { call!($i, <$crate::token::Lt as $crate::synom::Synom>::parse) }; |
| 403 | ($i:expr, *=) => { call!($i, <$crate::token::MulEq as $crate::synom::Synom>::parse) }; |
| 404 | ($i:expr, !=) => { call!($i, <$crate::token::Ne as $crate::synom::Synom>::parse) }; |
| 405 | ($i:expr, |) => { call!($i, <$crate::token::Or as $crate::synom::Synom>::parse) }; |
| 406 | ($i:expr, |=) => { call!($i, <$crate::token::OrEq as $crate::synom::Synom>::parse) }; |
| 407 | ($i:expr, ||) => { call!($i, <$crate::token::OrOr as $crate::synom::Synom>::parse) }; |
| 408 | ($i:expr, #) => { call!($i, <$crate::token::Pound as $crate::synom::Synom>::parse) }; |
| 409 | ($i:expr, ?) => { call!($i, <$crate::token::Question as $crate::synom::Synom>::parse) }; |
| 410 | ($i:expr, ->) => { call!($i, <$crate::token::RArrow as $crate::synom::Synom>::parse) }; |
| 411 | ($i:expr, <-) => { call!($i, <$crate::token::LArrow as $crate::synom::Synom>::parse) }; |
| 412 | ($i:expr, %) => { call!($i, <$crate::token::Rem as $crate::synom::Synom>::parse) }; |
| 413 | ($i:expr, %=) => { call!($i, <$crate::token::RemEq as $crate::synom::Synom>::parse) }; |
| 414 | ($i:expr, =>) => { call!($i, <$crate::token::Rocket as $crate::synom::Synom>::parse) }; |
| 415 | ($i:expr, ;) => { call!($i, <$crate::token::Semi as $crate::synom::Synom>::parse) }; |
| 416 | ($i:expr, <<) => { call!($i, <$crate::token::Shl as $crate::synom::Synom>::parse) }; |
| 417 | ($i:expr, <<=) => { call!($i, <$crate::token::ShlEq as $crate::synom::Synom>::parse) }; |
| 418 | ($i:expr, >>) => { call!($i, <$crate::token::Shr as $crate::synom::Synom>::parse) }; |
| 419 | ($i:expr, >>=) => { call!($i, <$crate::token::ShrEq as $crate::synom::Synom>::parse) }; |
| 420 | ($i:expr, *) => { call!($i, <$crate::token::Star as $crate::synom::Synom>::parse) }; |
| 421 | ($i:expr, -) => { call!($i, <$crate::token::Sub as $crate::synom::Synom>::parse) }; |
| 422 | ($i:expr, -=) => { call!($i, <$crate::token::SubEq as $crate::synom::Synom>::parse) }; |
| 423 | ($i:expr, _) => { call!($i, <$crate::token::Underscore as $crate::synom::Synom>::parse) }; |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 424 | } |
| 425 | |
David Tolnay | 0fbe328 | 2017-12-26 21:46:16 -0500 | [diff] [blame] | 426 | #[cfg(feature = "parsing")] |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 427 | #[macro_export] |
| 428 | macro_rules! keyword { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 429 | ($i:expr, as) => { call!($i, <$crate::token::As as $crate::synom::Synom>::parse) }; |
| 430 | ($i:expr, auto) => { call!($i, <$crate::token::Auto as $crate::synom::Synom>::parse) }; |
| 431 | ($i:expr, box) => { call!($i, <$crate::token::Box as $crate::synom::Synom>::parse) }; |
| 432 | ($i:expr, break) => { call!($i, <$crate::token::Break as $crate::synom::Synom>::parse) }; |
| 433 | ($i:expr, Self) => { call!($i, <$crate::token::CapSelf as $crate::synom::Synom>::parse) }; |
| 434 | ($i:expr, catch) => { call!($i, <$crate::token::Catch as $crate::synom::Synom>::parse) }; |
| 435 | ($i:expr, const) => { call!($i, <$crate::token::Const as $crate::synom::Synom>::parse) }; |
| 436 | ($i:expr, continue) => { call!($i, <$crate::token::Continue as $crate::synom::Synom>::parse) }; |
| 437 | ($i:expr, crate) => { call!($i, <$crate::token::Crate as $crate::synom::Synom>::parse) }; |
| 438 | ($i:expr, default) => { call!($i, <$crate::token::Default as $crate::synom::Synom>::parse) }; |
| 439 | ($i:expr, do) => { call!($i, <$crate::token::Do as $crate::synom::Synom>::parse) }; |
| 440 | ($i:expr, dyn) => { call!($i, <$crate::token::Dyn as $crate::synom::Synom>::parse) }; |
| 441 | ($i:expr, else) => { call!($i, <$crate::token::Else as $crate::synom::Synom>::parse) }; |
| 442 | ($i:expr, enum) => { call!($i, <$crate::token::Enum as $crate::synom::Synom>::parse) }; |
| 443 | ($i:expr, extern) => { call!($i, <$crate::token::Extern as $crate::synom::Synom>::parse) }; |
| 444 | ($i:expr, fn) => { call!($i, <$crate::token::Fn as $crate::synom::Synom>::parse) }; |
| 445 | ($i:expr, for) => { call!($i, <$crate::token::For as $crate::synom::Synom>::parse) }; |
| 446 | ($i:expr, if) => { call!($i, <$crate::token::If as $crate::synom::Synom>::parse) }; |
| 447 | ($i:expr, impl) => { call!($i, <$crate::token::Impl as $crate::synom::Synom>::parse) }; |
| 448 | ($i:expr, in) => { call!($i, <$crate::token::In as $crate::synom::Synom>::parse) }; |
| 449 | ($i:expr, let) => { call!($i, <$crate::token::Let as $crate::synom::Synom>::parse) }; |
| 450 | ($i:expr, loop) => { call!($i, <$crate::token::Loop as $crate::synom::Synom>::parse) }; |
| 451 | ($i:expr, macro) => { call!($i, <$crate::token::Macro as $crate::synom::Synom>::parse) }; |
| 452 | ($i:expr, match) => { call!($i, <$crate::token::Match as $crate::synom::Synom>::parse) }; |
| 453 | ($i:expr, mod) => { call!($i, <$crate::token::Mod as $crate::synom::Synom>::parse) }; |
| 454 | ($i:expr, move) => { call!($i, <$crate::token::Move as $crate::synom::Synom>::parse) }; |
| 455 | ($i:expr, mut) => { call!($i, <$crate::token::Mut as $crate::synom::Synom>::parse) }; |
| 456 | ($i:expr, pub) => { call!($i, <$crate::token::Pub as $crate::synom::Synom>::parse) }; |
| 457 | ($i:expr, ref) => { call!($i, <$crate::token::Ref as $crate::synom::Synom>::parse) }; |
| 458 | ($i:expr, return) => { call!($i, <$crate::token::Return as $crate::synom::Synom>::parse) }; |
| 459 | ($i:expr, self) => { call!($i, <$crate::token::Self_ as $crate::synom::Synom>::parse) }; |
| 460 | ($i:expr, static) => { call!($i, <$crate::token::Static as $crate::synom::Synom>::parse) }; |
| 461 | ($i:expr, struct) => { call!($i, <$crate::token::Struct as $crate::synom::Synom>::parse) }; |
| 462 | ($i:expr, super) => { call!($i, <$crate::token::Super as $crate::synom::Synom>::parse) }; |
| 463 | ($i:expr, trait) => { call!($i, <$crate::token::Trait as $crate::synom::Synom>::parse) }; |
| 464 | ($i:expr, type) => { call!($i, <$crate::token::Type as $crate::synom::Synom>::parse) }; |
| 465 | ($i:expr, union) => { call!($i, <$crate::token::Union as $crate::synom::Synom>::parse) }; |
| 466 | ($i:expr, unsafe) => { call!($i, <$crate::token::Unsafe as $crate::synom::Synom>::parse) }; |
| 467 | ($i:expr, use) => { call!($i, <$crate::token::Use as $crate::synom::Synom>::parse) }; |
| 468 | ($i:expr, where) => { call!($i, <$crate::token::Where as $crate::synom::Synom>::parse) }; |
| 469 | ($i:expr, while) => { call!($i, <$crate::token::While as $crate::synom::Synom>::parse) }; |
| 470 | ($i:expr, yield) => { call!($i, <$crate::token::Yield as $crate::synom::Synom>::parse) }; |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 471 | } |
| 472 | |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 473 | #[cfg(feature = "parsing")] |
| 474 | mod parsing { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 475 | use proc_macro2::{Delimiter, Spacing, Span}; |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 476 | |
David Tolnay | c5ab8c6 | 2017-12-26 16:43:39 -0500 | [diff] [blame] | 477 | use cursor::Cursor; |
David Tolnay | 203557a | 2017-12-27 23:59:33 -0500 | [diff] [blame] | 478 | use parse_error; |
| 479 | use synom::PResult; |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 480 | |
| 481 | pub trait FromSpans: Sized { |
| 482 | fn from_spans(spans: &[Span]) -> Self; |
| 483 | } |
| 484 | |
| 485 | impl FromSpans for [Span; 1] { |
| 486 | fn from_spans(spans: &[Span]) -> Self { |
| 487 | [spans[0]] |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | impl FromSpans for [Span; 2] { |
| 492 | fn from_spans(spans: &[Span]) -> Self { |
| 493 | [spans[0], spans[1]] |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | impl FromSpans for [Span; 3] { |
| 498 | fn from_spans(spans: &[Span]) -> Self { |
| 499 | [spans[0], spans[1], spans[2]] |
| 500 | } |
| 501 | } |
| 502 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 503 | pub fn punct<'a, T, R>(s: &str, mut tokens: Cursor<'a>, new: fn(T) -> R) -> PResult<'a, R> |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 504 | where |
| 505 | T: FromSpans, |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 506 | { |
| 507 | let mut spans = [Span::default(); 3]; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 508 | assert!(s.len() <= spans.len()); |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 509 | let chars = s.chars(); |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 510 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 511 | for (i, (ch, slot)) in chars.zip(&mut spans).enumerate() { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 512 | match tokens.op() { |
David Tolnay | 6572948 | 2017-12-31 16:14:50 -0500 | [diff] [blame^] | 513 | Some((span, op, kind, rest)) if op == ch => { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 514 | if i != s.len() - 1 { |
Alex Crichton | f9e8f1a | 2017-07-05 18:20:44 -0700 | [diff] [blame] | 515 | match kind { |
| 516 | Spacing::Joint => {} |
| 517 | _ => return parse_error(), |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 518 | } |
| 519 | } |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 520 | *slot = span; |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 521 | tokens = rest; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 522 | } |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 523 | _ => return parse_error(), |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 524 | } |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 525 | } |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 526 | Ok((tokens, new(T::from_spans(&spans)))) |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 527 | } |
| 528 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 529 | pub fn keyword<'a, T>(keyword: &str, tokens: Cursor<'a>, new: fn(Span) -> T) -> PResult<'a, T> { |
David Tolnay | 6572948 | 2017-12-31 16:14:50 -0500 | [diff] [blame^] | 530 | if let Some((span, term, rest)) = tokens.term() { |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 531 | if term.as_str() == keyword { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 532 | return Ok((rest, new(span))); |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 533 | } |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 534 | } |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 535 | parse_error() |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 536 | } |
| 537 | |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 538 | pub fn delim<'a, F, R, T>( |
| 539 | delim: &str, |
| 540 | tokens: Cursor<'a>, |
| 541 | new: fn(Span) -> T, |
| 542 | f: F, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 543 | ) -> PResult<'a, (T, R)> |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 544 | where |
| 545 | F: FnOnce(Cursor) -> PResult<R>, |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 546 | { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 547 | // NOTE: We should support none-delimited sequences here. |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 548 | let delim = match delim { |
| 549 | "(" => Delimiter::Parenthesis, |
| 550 | "{" => Delimiter::Brace, |
| 551 | "[" => Delimiter::Bracket, |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 552 | " " => Delimiter::None, |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 553 | _ => panic!("unknown delimiter: {}", delim), |
| 554 | }; |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 555 | |
David Tolnay | 6572948 | 2017-12-31 16:14:50 -0500 | [diff] [blame^] | 556 | if let Some((inside, span, rest)) = tokens.group(delim) { |
| 557 | match f(inside) { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 558 | Ok((remaining, ret)) => { |
| 559 | if remaining.eof() { |
David Tolnay | 6572948 | 2017-12-31 16:14:50 -0500 | [diff] [blame^] | 560 | return Ok((rest, (new(span), ret))); |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 561 | } |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 562 | } |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 563 | Err(err) => return Err(err), |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 564 | } |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 565 | } |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 566 | parse_error() |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | #[cfg(feature = "printing")] |
| 571 | mod printing { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 572 | use proc_macro2::{Spacing, Span, Term, TokenNode, TokenTree}; |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 573 | use quote::Tokens; |
| 574 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 575 | pub fn punct(s: &str, spans: &[Span], tokens: &mut Tokens) { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 576 | assert_eq!(s.len(), spans.len()); |
| 577 | |
| 578 | let mut chars = s.chars(); |
| 579 | let mut spans = spans.iter(); |
| 580 | let ch = chars.next_back().unwrap(); |
| 581 | let span = spans.next_back().unwrap(); |
| 582 | for (ch, span) in chars.zip(spans) { |
| 583 | tokens.append(TokenTree { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 584 | span: *span, |
Alex Crichton | f9e8f1a | 2017-07-05 18:20:44 -0700 | [diff] [blame] | 585 | kind: TokenNode::Op(ch, Spacing::Joint), |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 586 | }); |
| 587 | } |
| 588 | |
| 589 | tokens.append(TokenTree { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 590 | span: *span, |
Alex Crichton | f9e8f1a | 2017-07-05 18:20:44 -0700 | [diff] [blame] | 591 | kind: TokenNode::Op(ch, Spacing::Alone), |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 592 | }); |
| 593 | } |
| 594 | |
David Tolnay | 73c98de | 2017-12-31 15:56:56 -0500 | [diff] [blame] | 595 | pub fn keyword(s: &str, span: &Span, tokens: &mut Tokens) { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 596 | tokens.append(TokenTree { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 597 | span: *span, |
Alex Crichton | f9e8f1a | 2017-07-05 18:20:44 -0700 | [diff] [blame] | 598 | kind: TokenNode::Term(Term::intern(s)), |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 599 | }); |
| 600 | } |
| 601 | |
| 602 | pub fn delim<F>(s: &str, span: &Span, tokens: &mut Tokens, f: F) |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 603 | where |
| 604 | F: FnOnce(&mut Tokens), |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 605 | { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 606 | tokens.append_delimited(s, *span, f) |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 607 | } |
| 608 | } |