David Tolnay | 5553501 | 2018-01-05 16:39:23 -0800 | [diff] [blame] | 1 | // Copyright 2018 Syn Developers |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. This file may not be copied, modified, or distributed |
| 7 | // except according to those terms. |
| 8 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 9 | use super::*; |
David Tolnay | e303b7c | 2018-05-20 16:46:35 -0700 | [diff] [blame] | 10 | use proc_macro2::{Span, TokenStream}; |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 11 | use punctuated::Punctuated; |
David Tolnay | 1498201 | 2017-12-29 00:49:51 -0500 | [diff] [blame] | 12 | #[cfg(feature = "extra-traits")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 13 | use std::hash::{Hash, Hasher}; |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 14 | #[cfg(feature = "full")] |
| 15 | use std::mem; |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 16 | #[cfg(feature = "extra-traits")] |
| 17 | use tt::TokenStreamHelper; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 18 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 19 | ast_enum_of_structs! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 20 | /// A Rust expression. |
David Tolnay | 614a014 | 2018-01-07 10:25:43 -0800 | [diff] [blame] | 21 | /// |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 22 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 23 | /// feature.* |
| 24 | /// |
David Tolnay | 614a014 | 2018-01-07 10:25:43 -0800 | [diff] [blame] | 25 | /// # Syntax tree enums |
| 26 | /// |
| 27 | /// This type is a syntax tree enum. In Syn this and other syntax tree enums |
| 28 | /// are designed to be traversed using the following rebinding idiom. |
| 29 | /// |
| 30 | /// ``` |
| 31 | /// # use syn::Expr; |
| 32 | /// # |
| 33 | /// # fn example(expr: Expr) { |
| 34 | /// # const IGNORE: &str = stringify! { |
| 35 | /// let expr: Expr = /* ... */; |
| 36 | /// # }; |
| 37 | /// match expr { |
| 38 | /// Expr::MethodCall(expr) => { |
| 39 | /// /* ... */ |
| 40 | /// } |
| 41 | /// Expr::Cast(expr) => { |
| 42 | /// /* ... */ |
| 43 | /// } |
| 44 | /// Expr::IfLet(expr) => { |
| 45 | /// /* ... */ |
| 46 | /// } |
| 47 | /// /* ... */ |
| 48 | /// # _ => {} |
| 49 | /// } |
| 50 | /// # } |
| 51 | /// ``` |
| 52 | /// |
| 53 | /// We begin with a variable `expr` of type `Expr` that has no fields |
| 54 | /// (because it is an enum), and by matching on it and rebinding a variable |
| 55 | /// with the same name `expr` we effectively imbue our variable with all of |
| 56 | /// the data fields provided by the variant that it turned out to be. So for |
| 57 | /// example above if we ended up in the `MethodCall` case then we get to use |
| 58 | /// `expr.receiver`, `expr.args` etc; if we ended up in the `IfLet` case we |
| 59 | /// get to use `expr.pat`, `expr.then_branch`, `expr.else_branch`. |
| 60 | /// |
| 61 | /// The pattern is similar if the input expression is borrowed: |
| 62 | /// |
| 63 | /// ``` |
| 64 | /// # use syn::Expr; |
| 65 | /// # |
| 66 | /// # fn example(expr: &Expr) { |
| 67 | /// match *expr { |
| 68 | /// Expr::MethodCall(ref expr) => { |
| 69 | /// # } |
| 70 | /// # _ => {} |
| 71 | /// # } |
| 72 | /// # } |
| 73 | /// ``` |
| 74 | /// |
| 75 | /// This approach avoids repeating the variant names twice on every line. |
| 76 | /// |
| 77 | /// ``` |
| 78 | /// # use syn::{Expr, ExprMethodCall}; |
| 79 | /// # |
| 80 | /// # fn example(expr: Expr) { |
| 81 | /// # match expr { |
| 82 | /// Expr::MethodCall(ExprMethodCall { method, args, .. }) => { // repetitive |
| 83 | /// # } |
| 84 | /// # _ => {} |
| 85 | /// # } |
| 86 | /// # } |
| 87 | /// ``` |
| 88 | /// |
| 89 | /// In general, the name to which a syntax tree enum variant is bound should |
| 90 | /// be a suitable name for the complete syntax tree enum type. |
| 91 | /// |
| 92 | /// ``` |
| 93 | /// # use syn::{Expr, ExprField}; |
| 94 | /// # |
| 95 | /// # fn example(discriminant: &ExprField) { |
| 96 | /// // Binding is called `base` which is the name I would use if I were |
| 97 | /// // assigning `*discriminant.base` without an `if let`. |
| 98 | /// if let Expr::Tuple(ref base) = *discriminant.base { |
| 99 | /// # } |
| 100 | /// # } |
| 101 | /// ``` |
| 102 | /// |
| 103 | /// A sign that you may not be choosing the right variable names is if you |
| 104 | /// see names getting repeated in your code, like accessing |
| 105 | /// `receiver.receiver` or `pat.pat` or `cond.cond`. |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 106 | pub enum Expr { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 107 | /// A box expression: `box f`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 108 | /// |
| 109 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 110 | pub Box(ExprBox #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 111 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 112 | pub box_token: Token![box], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 113 | pub expr: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 114 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 115 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 116 | /// A placement expression: `place <- value`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 117 | /// |
| 118 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 119 | pub InPlace(ExprInPlace #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 120 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 121 | pub place: Box<Expr>, |
David Tolnay | 8701a5c | 2017-12-28 23:31:10 -0500 | [diff] [blame] | 122 | pub arrow_token: Token![<-], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 123 | pub value: Box<Expr>, |
| 124 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 125 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 126 | /// A slice literal expression: `[a, b, c, d]`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 127 | /// |
| 128 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 129 | pub Array(ExprArray #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 130 | pub attrs: Vec<Attribute>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 131 | pub bracket_token: token::Bracket, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 132 | pub elems: Punctuated<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 133 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 134 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 135 | /// A function call expression: `invoke(a, b)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 136 | /// |
| 137 | /// *This type is available if Syn is built with the `"derive"` or |
| 138 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 139 | pub Call(ExprCall { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 140 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 141 | pub func: Box<Expr>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 142 | pub paren_token: token::Paren, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 143 | pub args: Punctuated<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 144 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 145 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 146 | /// A method call expression: `x.foo::<T>(a, b)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 147 | /// |
| 148 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 149 | pub MethodCall(ExprMethodCall #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 150 | pub attrs: Vec<Attribute>, |
David Tolnay | 7641851 | 2017-12-28 23:47:47 -0500 | [diff] [blame] | 151 | pub receiver: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 152 | pub dot_token: Token![.], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 153 | pub method: Ident, |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 154 | pub turbofish: Option<MethodTurbofish>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 155 | pub paren_token: token::Paren, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 156 | pub args: Punctuated<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 157 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 158 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 159 | /// A tuple expression: `(a, b, c, d)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 160 | /// |
| 161 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 162 | pub Tuple(ExprTuple #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 163 | pub attrs: Vec<Attribute>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 164 | pub paren_token: token::Paren, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 165 | pub elems: Punctuated<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 166 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 167 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 168 | /// A binary operation: `a + b`, `a * b`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 169 | /// |
| 170 | /// *This type is available if Syn is built with the `"derive"` or |
| 171 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 172 | pub Binary(ExprBinary { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 173 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 174 | pub left: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 175 | pub op: BinOp, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 176 | pub right: Box<Expr>, |
| 177 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 178 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 179 | /// A unary operation: `!x`, `*x`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 180 | /// |
| 181 | /// *This type is available if Syn is built with the `"derive"` or |
| 182 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 183 | pub Unary(ExprUnary { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 184 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 185 | pub op: UnOp, |
| 186 | pub expr: Box<Expr>, |
| 187 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 188 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 189 | /// A literal in place of an expression: `1`, `"foo"`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 190 | /// |
| 191 | /// *This type is available if Syn is built with the `"derive"` or |
| 192 | /// `"full"` feature.* |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 193 | pub Lit(ExprLit { |
| 194 | pub attrs: Vec<Attribute>, |
| 195 | pub lit: Lit, |
| 196 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 197 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 198 | /// A cast expression: `foo as f64`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 199 | /// |
| 200 | /// *This type is available if Syn is built with the `"derive"` or |
| 201 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 202 | pub Cast(ExprCast { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 203 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 204 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 205 | pub as_token: Token![as], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 206 | pub ty: Box<Type>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 207 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 208 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 209 | /// A type ascription expression: `foo: f64`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 210 | /// |
| 211 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 212 | pub Type(ExprType #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 213 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 214 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 215 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 216 | pub ty: Box<Type>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 217 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 218 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 219 | /// An `if` expression with an optional `else` block: `if expr { ... } |
| 220 | /// else { ... }`. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 221 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 222 | /// The `else` branch expression may only be an `If`, `IfLet`, or |
| 223 | /// `Block` expression, not any of the other types of expression. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 224 | /// |
| 225 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 226 | pub If(ExprIf #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 227 | pub attrs: Vec<Attribute>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 228 | pub if_token: Token![if], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 229 | pub cond: Box<Expr>, |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 230 | pub then_branch: Block, |
| 231 | pub else_branch: Option<(Token![else], Box<Expr>)>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 232 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 233 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 234 | /// An `if let` expression with an optional `else` block: `if let pat = |
| 235 | /// expr { ... } else { ... }`. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 236 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 237 | /// The `else` branch expression may only be an `If`, `IfLet`, or |
| 238 | /// `Block` expression, not any of the other types of expression. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 239 | /// |
| 240 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 241 | pub IfLet(ExprIfLet #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 242 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 243 | pub if_token: Token![if], |
| 244 | pub let_token: Token![let], |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 245 | pub pats: Punctuated<Pat, Token![|]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 246 | pub eq_token: Token![=], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 247 | pub expr: Box<Expr>, |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 248 | pub then_branch: Block, |
| 249 | pub else_branch: Option<(Token![else], Box<Expr>)>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 250 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 251 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 252 | /// A while loop: `while expr { ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 253 | /// |
| 254 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 255 | pub While(ExprWhile #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 256 | pub attrs: Vec<Attribute>, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 257 | pub label: Option<Label>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 258 | pub while_token: Token![while], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 259 | pub cond: Box<Expr>, |
| 260 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 261 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 262 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 263 | /// A while-let loop: `while let pat = expr { ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 264 | /// |
| 265 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 266 | pub WhileLet(ExprWhileLet #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 267 | pub attrs: Vec<Attribute>, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 268 | pub label: Option<Label>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 269 | pub while_token: Token![while], |
| 270 | pub let_token: Token![let], |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 271 | pub pats: Punctuated<Pat, Token![|]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 272 | pub eq_token: Token![=], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 273 | pub expr: Box<Expr>, |
| 274 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 275 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 276 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 277 | /// A for loop: `for pat in expr { ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 278 | /// |
| 279 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 280 | pub ForLoop(ExprForLoop #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 281 | pub attrs: Vec<Attribute>, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 282 | pub label: Option<Label>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 283 | pub for_token: Token![for], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 284 | pub pat: Box<Pat>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 285 | pub in_token: Token![in], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 286 | pub expr: Box<Expr>, |
| 287 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 288 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 289 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 290 | /// Conditionless loop: `loop { ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 291 | /// |
| 292 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 293 | pub Loop(ExprLoop #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 294 | pub attrs: Vec<Attribute>, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 295 | pub label: Option<Label>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 296 | pub loop_token: Token![loop], |
| 297 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 298 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 299 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 300 | /// A `match` expression: `match n { Some(n) => {}, None => {} }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 301 | /// |
| 302 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 303 | pub Match(ExprMatch #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 304 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 305 | pub match_token: Token![match], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 306 | pub expr: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 307 | pub brace_token: token::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 308 | pub arms: Vec<Arm>, |
| 309 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 310 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 311 | /// A closure expression: `|a, b| a + b`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 312 | /// |
| 313 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 314 | pub Closure(ExprClosure #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 315 | pub attrs: Vec<Attribute>, |
Yusuke Sasaki | 4e5d966 | 2018-07-21 02:49:47 +0900 | [diff] [blame] | 316 | pub asyncness: Option<Token![async]>, |
David Tolnay | 13d4c0e | 2018-03-31 20:53:59 +0200 | [diff] [blame] | 317 | pub movability: Option<Token![static]>, |
David Tolnay | efc96fb | 2017-12-29 02:03:15 -0500 | [diff] [blame] | 318 | pub capture: Option<Token![move]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 319 | pub or1_token: Token![|], |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 320 | pub inputs: Punctuated<FnArg, Token![,]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 321 | pub or2_token: Token![|], |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 322 | pub output: ReturnType, |
| 323 | pub body: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 324 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 325 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 326 | /// An unsafe block: `unsafe { ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 327 | /// |
| 328 | /// *This type is available if Syn is built with the `"full"` feature.* |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 329 | pub Unsafe(ExprUnsafe #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 330 | pub attrs: Vec<Attribute>, |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 331 | pub unsafe_token: Token![unsafe], |
| 332 | pub block: Block, |
| 333 | }), |
| 334 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 335 | /// A blocked scope: `{ ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 336 | /// |
| 337 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 338 | pub Block(ExprBlock #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 339 | pub attrs: Vec<Attribute>, |
David Tolnay | 1d8e996 | 2018-08-24 19:04:20 -0400 | [diff] [blame] | 340 | pub label: Option<Label>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 341 | pub block: Block, |
| 342 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 343 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 344 | /// An assignment expression: `a = compute()`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 345 | /// |
| 346 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 347 | pub Assign(ExprAssign #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 348 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 349 | pub left: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 350 | pub eq_token: Token![=], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 351 | pub right: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 352 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 353 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 354 | /// A compound assignment expression: `counter += 1`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 355 | /// |
| 356 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 357 | pub AssignOp(ExprAssignOp #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 358 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 359 | pub left: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 360 | pub op: BinOp, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 361 | pub right: Box<Expr>, |
| 362 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 363 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 364 | /// Access of a named struct field (`obj.k`) or unnamed tuple struct |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 365 | /// field (`obj.0`). |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 366 | /// |
| 367 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | d514774 | 2018-06-30 10:09:52 -0700 | [diff] [blame] | 368 | pub Field(ExprField { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 369 | pub attrs: Vec<Attribute>, |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 370 | pub base: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 371 | pub dot_token: Token![.], |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 372 | pub member: Member, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 373 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 374 | |
David Tolnay | 0565850 | 2018-01-07 09:56:37 -0800 | [diff] [blame] | 375 | /// A square bracketed indexing expression: `vector[2]`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 376 | /// |
| 377 | /// *This type is available if Syn is built with the `"derive"` or |
| 378 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 379 | pub Index(ExprIndex { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 380 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 381 | pub expr: Box<Expr>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 382 | pub bracket_token: token::Bracket, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 383 | pub index: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 384 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 385 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 386 | /// A range expression: `1..2`, `1..`, `..2`, `1..=2`, `..=2`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 387 | /// |
| 388 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 389 | pub Range(ExprRange #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 390 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 391 | pub from: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 392 | pub limits: RangeLimits, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 393 | pub to: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 394 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 395 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 396 | /// A path like `std::mem::replace` possibly containing generic |
| 397 | /// parameters and a qualified self-type. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 398 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 399 | /// A plain identifier like `x` is a path of length 1. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 400 | /// |
| 401 | /// *This type is available if Syn is built with the `"derive"` or |
| 402 | /// `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 403 | pub Path(ExprPath { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 404 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 405 | pub qself: Option<QSelf>, |
| 406 | pub path: Path, |
| 407 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 408 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 409 | /// A referencing operation: `&a` or `&mut a`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 410 | /// |
| 411 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 00674ba | 2018-03-31 18:14:11 +0200 | [diff] [blame] | 412 | pub Reference(ExprReference #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 413 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 414 | pub and_token: Token![&], |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 415 | pub mutability: Option<Token![mut]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 416 | pub expr: Box<Expr>, |
| 417 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 418 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 419 | /// A `break`, with an optional label to break and an optional |
| 420 | /// expression. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 421 | /// |
| 422 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 423 | pub Break(ExprBreak #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 424 | pub attrs: Vec<Attribute>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 425 | pub break_token: Token![break], |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 426 | pub label: Option<Lifetime>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 427 | pub expr: Option<Box<Expr>>, |
| 428 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 429 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 430 | /// A `continue`, with an optional label. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 431 | /// |
| 432 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 433 | pub Continue(ExprContinue #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 434 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 435 | pub continue_token: Token![continue], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 436 | pub label: Option<Lifetime>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 437 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 438 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 439 | /// A `return`, with an optional value to be returned. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 440 | /// |
| 441 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | c246cd3 | 2017-12-28 23:14:32 -0500 | [diff] [blame] | 442 | pub Return(ExprReturn #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 443 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 444 | pub return_token: Token![return], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 445 | pub expr: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 446 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 447 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 448 | /// A macro invocation expression: `format!("{}", q)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 449 | /// |
| 450 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 451 | pub Macro(ExprMacro #full { |
| 452 | pub attrs: Vec<Attribute>, |
| 453 | pub mac: Macro, |
| 454 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 455 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 456 | /// A struct literal expression: `Point { x: 1, y: 1 }`. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 457 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 458 | /// The `rest` provides the value of the remaining fields as in `S { a: |
| 459 | /// 1, b: 1, ..rest }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 460 | /// |
| 461 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 462 | pub Struct(ExprStruct #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 463 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 464 | pub path: Path, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 465 | pub brace_token: token::Brace, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 466 | pub fields: Punctuated<FieldValue, Token![,]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 467 | pub dot2_token: Option<Token![..]>, |
| 468 | pub rest: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 469 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 470 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 471 | /// An array literal constructed from one repeated element: `[0u8; N]`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 472 | /// |
| 473 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 474 | pub Repeat(ExprRepeat #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 475 | pub attrs: Vec<Attribute>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 476 | pub bracket_token: token::Bracket, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 477 | pub expr: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 478 | pub semi_token: Token![;], |
David Tolnay | 84d8044 | 2018-01-07 01:03:20 -0800 | [diff] [blame] | 479 | pub len: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 480 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 481 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 482 | /// A parenthesized expression: `(a + b)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 483 | /// |
| 484 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 9374bc0 | 2018-01-27 18:49:36 -0800 | [diff] [blame] | 485 | pub Paren(ExprParen { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 486 | pub attrs: Vec<Attribute>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 487 | pub paren_token: token::Paren, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 488 | pub expr: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 489 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 490 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 491 | /// An expression contained within invisible delimiters. |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 492 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 493 | /// This variant is important for faithfully representing the precedence |
| 494 | /// of expressions and is related to `None`-delimited spans in a |
| 495 | /// `TokenStream`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 496 | /// |
| 497 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | e98775f | 2017-12-28 23:17:00 -0500 | [diff] [blame] | 498 | pub Group(ExprGroup #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 499 | pub attrs: Vec<Attribute>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 500 | pub group_token: token::Group, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 501 | pub expr: Box<Expr>, |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 502 | }), |
| 503 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 504 | /// A try-expression: `expr?`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 505 | /// |
| 506 | /// *This type is available if Syn is built with the `"full"` feature.* |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 507 | pub Try(ExprTry #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 508 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 509 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 510 | pub question_token: Token![?], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 511 | }), |
Arnavion | 02ef13f | 2017-04-25 00:54:31 -0700 | [diff] [blame] | 512 | |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 513 | /// An async block: `async { ... }`. |
| 514 | /// |
| 515 | /// *This type is available if Syn is built with the `"full"` feature.* |
| 516 | pub Async(ExprAsync #full { |
| 517 | pub attrs: Vec<Attribute>, |
| 518 | pub async_token: Token![async], |
| 519 | pub capture: Option<Token![move]>, |
| 520 | pub block: Block, |
| 521 | }), |
| 522 | |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 523 | /// A try block: `try { ... }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 524 | /// |
| 525 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 526 | pub TryBlock(ExprTryBlock #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 527 | pub attrs: Vec<Attribute>, |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 528 | pub try_token: Token![try], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 529 | pub block: Block, |
| 530 | }), |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 531 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 532 | /// A yield expression: `yield expr`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 533 | /// |
| 534 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 535 | pub Yield(ExprYield #full { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 536 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 537 | pub yield_token: Token![yield], |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 538 | pub expr: Option<Box<Expr>>, |
| 539 | }), |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 540 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 541 | /// Tokens in expression position not interpreted by Syn. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 542 | /// |
| 543 | /// *This type is available if Syn is built with the `"derive"` or |
| 544 | /// `"full"` feature.* |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 545 | pub Verbatim(ExprVerbatim #manual_extra_traits { |
| 546 | pub tts: TokenStream, |
| 547 | }), |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | #[cfg(feature = "extra-traits")] |
| 552 | impl Eq for ExprVerbatim {} |
| 553 | |
| 554 | #[cfg(feature = "extra-traits")] |
| 555 | impl PartialEq for ExprVerbatim { |
| 556 | fn eq(&self, other: &Self) -> bool { |
| 557 | TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts) |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | #[cfg(feature = "extra-traits")] |
| 562 | impl Hash for ExprVerbatim { |
| 563 | fn hash<H>(&self, state: &mut H) |
| 564 | where |
| 565 | H: Hasher, |
| 566 | { |
| 567 | TokenStreamHelper(&self.tts).hash(state); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 568 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 569 | } |
| 570 | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 571 | impl Expr { |
| 572 | // Not public API. |
| 573 | #[doc(hidden)] |
David Tolnay | 096d498 | 2017-12-28 23:18:18 -0500 | [diff] [blame] | 574 | #[cfg(feature = "full")] |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 575 | pub fn replace_attrs(&mut self, new: Vec<Attribute>) -> Vec<Attribute> { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 576 | match *self { |
David Tolnay | 61037c6 | 2018-01-05 16:21:03 -0800 | [diff] [blame] | 577 | Expr::Box(ExprBox { ref mut attrs, .. }) |
| 578 | | Expr::InPlace(ExprInPlace { ref mut attrs, .. }) |
| 579 | | Expr::Array(ExprArray { ref mut attrs, .. }) |
| 580 | | Expr::Call(ExprCall { ref mut attrs, .. }) |
| 581 | | Expr::MethodCall(ExprMethodCall { ref mut attrs, .. }) |
| 582 | | Expr::Tuple(ExprTuple { ref mut attrs, .. }) |
| 583 | | Expr::Binary(ExprBinary { ref mut attrs, .. }) |
| 584 | | Expr::Unary(ExprUnary { ref mut attrs, .. }) |
| 585 | | Expr::Lit(ExprLit { ref mut attrs, .. }) |
| 586 | | Expr::Cast(ExprCast { ref mut attrs, .. }) |
| 587 | | Expr::Type(ExprType { ref mut attrs, .. }) |
| 588 | | Expr::If(ExprIf { ref mut attrs, .. }) |
| 589 | | Expr::IfLet(ExprIfLet { ref mut attrs, .. }) |
| 590 | | Expr::While(ExprWhile { ref mut attrs, .. }) |
| 591 | | Expr::WhileLet(ExprWhileLet { ref mut attrs, .. }) |
| 592 | | Expr::ForLoop(ExprForLoop { ref mut attrs, .. }) |
| 593 | | Expr::Loop(ExprLoop { ref mut attrs, .. }) |
| 594 | | Expr::Match(ExprMatch { ref mut attrs, .. }) |
| 595 | | Expr::Closure(ExprClosure { ref mut attrs, .. }) |
| 596 | | Expr::Unsafe(ExprUnsafe { ref mut attrs, .. }) |
| 597 | | Expr::Block(ExprBlock { ref mut attrs, .. }) |
| 598 | | Expr::Assign(ExprAssign { ref mut attrs, .. }) |
| 599 | | Expr::AssignOp(ExprAssignOp { ref mut attrs, .. }) |
| 600 | | Expr::Field(ExprField { ref mut attrs, .. }) |
| 601 | | Expr::Index(ExprIndex { ref mut attrs, .. }) |
| 602 | | Expr::Range(ExprRange { ref mut attrs, .. }) |
| 603 | | Expr::Path(ExprPath { ref mut attrs, .. }) |
David Tolnay | 00674ba | 2018-03-31 18:14:11 +0200 | [diff] [blame] | 604 | | Expr::Reference(ExprReference { ref mut attrs, .. }) |
David Tolnay | 61037c6 | 2018-01-05 16:21:03 -0800 | [diff] [blame] | 605 | | Expr::Break(ExprBreak { ref mut attrs, .. }) |
| 606 | | Expr::Continue(ExprContinue { ref mut attrs, .. }) |
| 607 | | Expr::Return(ExprReturn { ref mut attrs, .. }) |
| 608 | | Expr::Macro(ExprMacro { ref mut attrs, .. }) |
| 609 | | Expr::Struct(ExprStruct { ref mut attrs, .. }) |
| 610 | | Expr::Repeat(ExprRepeat { ref mut attrs, .. }) |
| 611 | | Expr::Paren(ExprParen { ref mut attrs, .. }) |
| 612 | | Expr::Group(ExprGroup { ref mut attrs, .. }) |
| 613 | | Expr::Try(ExprTry { ref mut attrs, .. }) |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 614 | | Expr::Async(ExprAsync { ref mut attrs, .. }) |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 615 | | Expr::TryBlock(ExprTryBlock { ref mut attrs, .. }) |
David Tolnay | 61037c6 | 2018-01-05 16:21:03 -0800 | [diff] [blame] | 616 | | Expr::Yield(ExprYield { ref mut attrs, .. }) => mem::replace(attrs, new), |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 617 | Expr::Verbatim(_) => { |
| 618 | // TODO |
| 619 | Vec::new() |
| 620 | } |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | } |
| 624 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 625 | ast_enum! { |
| 626 | /// A struct or tuple struct field accessed in a struct literal or field |
| 627 | /// expression. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 628 | /// |
| 629 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 630 | /// feature.* |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 631 | pub enum Member { |
| 632 | /// A named field like `self.x`. |
| 633 | Named(Ident), |
| 634 | /// An unnamed field like `self.0`. |
| 635 | Unnamed(Index), |
| 636 | } |
| 637 | } |
| 638 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 639 | ast_struct! { |
| 640 | /// The index of an unnamed tuple struct field. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 641 | /// |
| 642 | /// *This type is available if Syn is built with the `"derive"` or `"full"` |
| 643 | /// feature.* |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 644 | pub struct Index #manual_extra_traits { |
| 645 | pub index: u32, |
| 646 | pub span: Span, |
| 647 | } |
| 648 | } |
| 649 | |
David Tolnay | 1498201 | 2017-12-29 00:49:51 -0500 | [diff] [blame] | 650 | impl From<usize> for Index { |
| 651 | fn from(index: usize) -> Index { |
David Tolnay | 34071ba | 2018-05-20 20:00:41 -0700 | [diff] [blame] | 652 | assert!(index < u32::max_value() as usize); |
David Tolnay | 1498201 | 2017-12-29 00:49:51 -0500 | [diff] [blame] | 653 | Index { |
| 654 | index: index as u32, |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 655 | span: Span::call_site(), |
David Tolnay | 1498201 | 2017-12-29 00:49:51 -0500 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | #[cfg(feature = "extra-traits")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 661 | impl Eq for Index {} |
| 662 | |
David Tolnay | 1498201 | 2017-12-29 00:49:51 -0500 | [diff] [blame] | 663 | #[cfg(feature = "extra-traits")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 664 | impl PartialEq for Index { |
| 665 | fn eq(&self, other: &Self) -> bool { |
| 666 | self.index == other.index |
| 667 | } |
| 668 | } |
| 669 | |
David Tolnay | 1498201 | 2017-12-29 00:49:51 -0500 | [diff] [blame] | 670 | #[cfg(feature = "extra-traits")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 671 | impl Hash for Index { |
| 672 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 673 | self.index.hash(state); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 678 | ast_struct! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 679 | /// The `::<>` explicit type parameters passed to a method call: |
| 680 | /// `parse::<u64>()`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 681 | /// |
| 682 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 683 | pub struct MethodTurbofish { |
| 684 | pub colon2_token: Token![::], |
| 685 | pub lt_token: Token![<], |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 686 | pub args: Punctuated<GenericMethodArgument, Token![,]>, |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 687 | pub gt_token: Token![>], |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | #[cfg(feature = "full")] |
| 692 | ast_enum! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 693 | /// An individual generic argument to a method, like `T`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 694 | /// |
| 695 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 696 | pub enum GenericMethodArgument { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 697 | /// A type argument. |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 698 | Type(Type), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 699 | /// A const expression. Must be inside of a block. |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 700 | /// |
| 701 | /// NOTE: Identity expressions are represented as Type arguments, as |
| 702 | /// they are indistinguishable syntactically. |
| 703 | Const(Expr), |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | #[cfg(feature = "full")] |
| 708 | ast_struct! { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 709 | /// A field-value pair in a struct literal. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 710 | /// |
| 711 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 712 | pub struct FieldValue { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 713 | /// Attributes tagged on the field. |
| 714 | pub attrs: Vec<Attribute>, |
| 715 | |
| 716 | /// Name or index of the field. |
| 717 | pub member: Member, |
| 718 | |
David Tolnay | 5d7098a | 2017-12-29 01:35:24 -0500 | [diff] [blame] | 719 | /// The colon in `Struct { x: x }`. If written in shorthand like |
| 720 | /// `Struct { x }`, there is no colon. |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 721 | pub colon_token: Option<Token![:]>, |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 722 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 723 | /// Value of the field. |
| 724 | pub expr: Expr, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 725 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 728 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 729 | ast_struct! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 730 | /// A lifetime labeling a `for`, `while`, or `loop`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 731 | /// |
| 732 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 733 | pub struct Label { |
| 734 | pub name: Lifetime, |
| 735 | pub colon_token: Token![:], |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | #[cfg(feature = "full")] |
| 740 | ast_struct! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 741 | /// A braced block containing Rust statements. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 742 | /// |
| 743 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 744 | pub struct Block { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 745 | pub brace_token: token::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 746 | /// Statements in a block |
| 747 | pub stmts: Vec<Stmt>, |
| 748 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 751 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 752 | ast_enum! { |
| 753 | /// A statement, usually ending in a semicolon. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 754 | /// |
| 755 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 756 | pub enum Stmt { |
| 757 | /// A local (let) binding. |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 758 | Local(Local), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 759 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 760 | /// An item definition. |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 761 | Item(Item), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 762 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 763 | /// Expr without trailing semicolon. |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 764 | Expr(Expr), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 765 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 766 | /// Expression with trailing semicolon. |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 767 | Semi(Expr, Token![;]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 768 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 771 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 772 | ast_struct! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 773 | /// A local `let` binding: `let x: u64 = s.parse()?`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 774 | /// |
| 775 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 776 | pub struct Local { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 777 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 778 | pub let_token: Token![let], |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 779 | pub pats: Punctuated<Pat, Token![|]>, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 780 | pub ty: Option<(Token![:], Box<Type>)>, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 781 | pub init: Option<(Token![=], Box<Expr>)>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 782 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 783 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 786 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 787 | ast_enum_of_structs! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 788 | /// A pattern in a local binding, function signature, match expression, or |
| 789 | /// various other places. |
David Tolnay | 614a014 | 2018-01-07 10:25:43 -0800 | [diff] [blame] | 790 | /// |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 791 | /// *This type is available if Syn is built with the `"full"` feature.* |
| 792 | /// |
David Tolnay | 614a014 | 2018-01-07 10:25:43 -0800 | [diff] [blame] | 793 | /// # Syntax tree enum |
| 794 | /// |
| 795 | /// This type is a [syntax tree enum]. |
| 796 | /// |
| 797 | /// [syntax tree enum]: enum.Expr.html#syntax-tree-enums |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 798 | // Clippy false positive |
| 799 | // https://github.com/Manishearth/rust-clippy/issues/1241 |
| 800 | #[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))] |
| 801 | pub enum Pat { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 802 | /// A pattern that matches any value: `_`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 803 | /// |
| 804 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 805 | pub Wild(PatWild { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 806 | pub underscore_token: Token![_], |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 807 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 808 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 809 | /// A pattern that binds a new variable: `ref mut binding @ SUBPATTERN`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 810 | /// |
| 811 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 812 | pub Ident(PatIdent { |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 813 | pub by_ref: Option<Token![ref]>, |
| 814 | pub mutability: Option<Token![mut]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 815 | pub ident: Ident, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 816 | pub subpat: Option<(Token![@], Box<Pat>)>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 817 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 818 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 819 | /// A struct or struct variant pattern: `Variant { x, y, .. }`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 820 | /// |
| 821 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 822 | pub Struct(PatStruct { |
| 823 | pub path: Path, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 824 | pub brace_token: token::Brace, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 825 | pub fields: Punctuated<FieldPat, Token![,]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 826 | pub dot2_token: Option<Token![..]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 827 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 828 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 829 | /// A tuple struct or tuple variant pattern: `Variant(x, y, .., z)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 830 | /// |
| 831 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 832 | pub TupleStruct(PatTupleStruct { |
| 833 | pub path: Path, |
| 834 | pub pat: PatTuple, |
| 835 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 836 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 837 | /// A path pattern like `Color::Red`, optionally qualified with a |
| 838 | /// self-type. |
| 839 | /// |
| 840 | /// Unquailfied path patterns can legally refer to variants, structs, |
| 841 | /// constants or associated constants. Quailfied path patterns like |
| 842 | /// `<A>::B::C` and `<A as Trait>::B::C` can only legally refer to |
| 843 | /// associated constants. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 844 | /// |
| 845 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 846 | pub Path(PatPath { |
| 847 | pub qself: Option<QSelf>, |
| 848 | pub path: Path, |
| 849 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 850 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 851 | /// A tuple pattern: `(a, b)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 852 | /// |
| 853 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 854 | pub Tuple(PatTuple { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 855 | pub paren_token: token::Paren, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 856 | pub front: Punctuated<Pat, Token![,]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 857 | pub dot2_token: Option<Token![..]>, |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 858 | pub comma_token: Option<Token![,]>, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 859 | pub back: Punctuated<Pat, Token![,]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 860 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 861 | |
| 862 | /// A box pattern: `box v`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 863 | /// |
| 864 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 865 | pub Box(PatBox { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 866 | pub box_token: Token![box], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 867 | pub pat: Box<Pat>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 868 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 869 | |
| 870 | /// A reference pattern: `&mut (first, second)`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 871 | /// |
| 872 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 873 | pub Ref(PatRef { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 874 | pub and_token: Token![&], |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 875 | pub mutability: Option<Token![mut]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 876 | pub pat: Box<Pat>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 877 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 878 | |
| 879 | /// A literal pattern: `0`. |
| 880 | /// |
| 881 | /// This holds an `Expr` rather than a `Lit` because negative numbers |
| 882 | /// are represented as an `Expr::Unary`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 883 | /// |
| 884 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 885 | pub Lit(PatLit { |
| 886 | pub expr: Box<Expr>, |
| 887 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 888 | |
| 889 | /// A range pattern: `1..=2`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 890 | /// |
| 891 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 892 | pub Range(PatRange { |
| 893 | pub lo: Box<Expr>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 894 | pub limits: RangeLimits, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 895 | pub hi: Box<Expr>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 896 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 897 | |
| 898 | /// A dynamically sized slice pattern: `[a, b, i.., y, z]`. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 899 | /// |
| 900 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 901 | pub Slice(PatSlice { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 902 | pub bracket_token: token::Bracket, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 903 | pub front: Punctuated<Pat, Token![,]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 904 | pub middle: Option<Box<Pat>>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 905 | pub dot2_token: Option<Token![..]>, |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 906 | pub comma_token: Option<Token![,]>, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 907 | pub back: Punctuated<Pat, Token![,]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 908 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 909 | |
| 910 | /// A macro in expression position. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 911 | /// |
| 912 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 323279a | 2017-12-29 11:26:32 -0500 | [diff] [blame] | 913 | pub Macro(PatMacro { |
| 914 | pub mac: Macro, |
| 915 | }), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 916 | |
| 917 | /// Tokens in pattern position not interpreted by Syn. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 918 | /// |
| 919 | /// *This type is available if Syn is built with the `"full"` feature.* |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 920 | pub Verbatim(PatVerbatim #manual_extra_traits { |
| 921 | pub tts: TokenStream, |
| 922 | }), |
| 923 | } |
| 924 | } |
| 925 | |
David Tolnay | c43b44e | 2017-12-30 23:55:54 -0500 | [diff] [blame] | 926 | #[cfg(all(feature = "full", feature = "extra-traits"))] |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 927 | impl Eq for PatVerbatim {} |
| 928 | |
David Tolnay | c43b44e | 2017-12-30 23:55:54 -0500 | [diff] [blame] | 929 | #[cfg(all(feature = "full", feature = "extra-traits"))] |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 930 | impl PartialEq for PatVerbatim { |
| 931 | fn eq(&self, other: &Self) -> bool { |
| 932 | TokenStreamHelper(&self.tts) == TokenStreamHelper(&other.tts) |
| 933 | } |
| 934 | } |
| 935 | |
David Tolnay | c43b44e | 2017-12-30 23:55:54 -0500 | [diff] [blame] | 936 | #[cfg(all(feature = "full", feature = "extra-traits"))] |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 937 | impl Hash for PatVerbatim { |
| 938 | fn hash<H>(&self, state: &mut H) |
| 939 | where |
| 940 | H: Hasher, |
| 941 | { |
| 942 | TokenStreamHelper(&self.tts).hash(state); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 943 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 946 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 947 | ast_struct! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 948 | /// One arm of a `match` expression: `0...10 => { return true; }`. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 949 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 950 | /// As in: |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 951 | /// |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 952 | /// ```rust |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 953 | /// # fn f() -> bool { |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 954 | /// # let n = 0; |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 955 | /// match n { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 956 | /// 0...10 => { |
| 957 | /// return true; |
| 958 | /// } |
| 959 | /// // ... |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 960 | /// # _ => {} |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 961 | /// } |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 962 | /// # false |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 963 | /// # } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 964 | /// ``` |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 965 | /// |
| 966 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 967 | pub struct Arm { |
| 968 | pub attrs: Vec<Attribute>, |
David Tolnay | 18cc4d4 | 2018-03-31 18:47:20 +0200 | [diff] [blame] | 969 | pub leading_vert: Option<Token![|]>, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 970 | pub pats: Punctuated<Pat, Token![|]>, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 971 | pub guard: Option<(Token![if], Box<Expr>)>, |
David Tolnay | dfb9143 | 2018-03-31 19:19:44 +0200 | [diff] [blame] | 972 | pub fat_arrow_token: Token![=>], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 973 | pub body: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 974 | pub comma: Option<Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 975 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 978 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 979 | ast_enum! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 980 | /// Limit types of a range, inclusive or exclusive. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 981 | /// |
| 982 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 983 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 984 | pub enum RangeLimits { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 985 | /// Inclusive at the beginning, exclusive at the end. |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 986 | HalfOpen(Token![..]), |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 987 | /// Inclusive at the beginning and end. |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 988 | Closed(Token![..=]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 989 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 992 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 993 | ast_struct! { |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 994 | /// A single field in a struct pattern. |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 995 | /// |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 996 | /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` are treated |
| 997 | /// the same as `x: x, y: ref y, z: ref mut z` but there is no colon token. |
David Tolnay | 461d98e | 2018-01-07 11:07:19 -0800 | [diff] [blame] | 998 | /// |
| 999 | /// *This type is available if Syn is built with the `"full"` feature.* |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1000 | pub struct FieldPat { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 1001 | pub attrs: Vec<Attribute>, |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1002 | pub member: Member, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame] | 1003 | pub colon_token: Option<Token![:]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1004 | pub pat: Box<Pat>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1005 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1008 | #[cfg(any(feature = "parsing", feature = "printing"))] |
| 1009 | #[cfg(feature = "full")] |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1010 | fn arm_expr_requires_comma(expr: &Expr) -> bool { |
| 1011 | // see https://github.com/rust-lang/rust/blob/eb8f2586e |
| 1012 | // /src/libsyntax/parse/classify.rs#L17-L37 |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1013 | match *expr { |
| 1014 | Expr::Unsafe(..) |
| 1015 | | Expr::Block(..) |
| 1016 | | Expr::If(..) |
| 1017 | | Expr::IfLet(..) |
| 1018 | | Expr::Match(..) |
| 1019 | | Expr::While(..) |
| 1020 | | Expr::WhileLet(..) |
| 1021 | | Expr::Loop(..) |
| 1022 | | Expr::ForLoop(..) |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 1023 | | Expr::Async(..) |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 1024 | | Expr::TryBlock(..) => false, |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1025 | _ => true, |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 1029 | #[cfg(feature = "parsing")] |
| 1030 | pub mod parsing { |
| 1031 | use super::*; |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 1032 | use path::parsing::old_mod_style_path_segment; |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 1033 | #[cfg(feature = "full")] |
David Tolnay | 056de30 | 2018-01-05 14:29:05 -0800 | [diff] [blame] | 1034 | use path::parsing::ty_no_eq_after; |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 1035 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1036 | use parse::{Parse, ParseStream, Result}; |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1037 | #[cfg(feature = "full")] |
David Tolnay | c5ab8c6 | 2017-12-26 16:43:39 -0500 | [diff] [blame] | 1038 | use parse_error; |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 1039 | #[cfg(feature = "full")] |
| 1040 | use proc_macro2::TokenStream; |
David Tolnay | 94d2b79 | 2018-04-29 12:26:10 -0700 | [diff] [blame] | 1041 | use synom::Synom; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1042 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1043 | macro_rules! named2 { |
| 1044 | ($name:ident ($($arg:ident : $argty:ty),*) -> $ret:ty, $($rest:tt)*) => { |
| 1045 | fn $name(input: ParseStream $(, $arg : $argty)*) -> Result<$ret> { |
| 1046 | named!(_synom ($($arg : $argty),*) -> $ret, $($rest)*); |
| 1047 | input.step_cursor(|cursor| _synom(*cursor $(, $arg)*)) |
| 1048 | } |
| 1049 | }; |
| 1050 | ($name:ident -> $ret:ty, $($rest:tt)*) => { |
| 1051 | fn $name(input: ParseStream) -> Result<$ret> { |
| 1052 | named!(_synom -> $ret, $($rest)*); |
| 1053 | input.step_cursor(|cursor| _synom(*cursor)) |
| 1054 | } |
| 1055 | }; |
| 1056 | } |
| 1057 | |
| 1058 | #[cfg(feature = "full")] |
| 1059 | macro_rules! ambiguous_expr { |
| 1060 | ($i:expr, $allow_struct:ident) => { |
| 1061 | shim!($i, ambiguous_expr, $allow_struct, AllowBlock(true)) |
| 1062 | }; |
| 1063 | } |
| 1064 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1065 | // When we're parsing expressions which occur before blocks, like in an if |
| 1066 | // statement's condition, we cannot parse a struct literal. |
| 1067 | // |
| 1068 | // Struct literals are ambiguous in certain positions |
| 1069 | // https://github.com/rust-lang/rfcs/pull/92 |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1070 | #[derive(Copy, Clone)] |
| 1071 | pub struct AllowStruct(bool); |
| 1072 | |
| 1073 | #[derive(Copy, Clone)] |
| 1074 | pub struct AllowBlock(bool); |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 1075 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1076 | // When we are parsing an optional suffix expression, we cannot allow blocks |
| 1077 | // if structs are not allowed. |
| 1078 | // |
| 1079 | // Example: |
| 1080 | // |
| 1081 | // if break {} {} |
| 1082 | // |
| 1083 | // is ambiguous between: |
| 1084 | // |
| 1085 | // if (break {}) {} |
| 1086 | // if (break) {} {} |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1087 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1088 | macro_rules! opt_ambiguous_expr { |
| 1089 | ($i:expr, $allow_struct:ident) => { |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1090 | option!($i, shim!(ambiguous_expr, $allow_struct, AllowBlock($allow_struct.0))) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1091 | }; |
| 1092 | } |
| 1093 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1094 | impl Parse for Expr { |
| 1095 | fn parse(input: ParseStream) -> Result<Self> { |
| 1096 | ambiguous_expr(input, AllowStruct(true), AllowBlock(true)) |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1100 | #[cfg(feature = "full")] |
David Tolnay | 9fb0aed | 2018-08-27 10:23:12 -0700 | [diff] [blame] | 1101 | fn expr_no_struct(input: ParseStream) -> Result<Expr> { |
| 1102 | ambiguous_expr(input, AllowStruct(false), AllowBlock(true)) |
| 1103 | } |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 1104 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1105 | // Parse an arbitrary expression. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1106 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1107 | fn ambiguous_expr(input: ParseStream, allow_struct: AllowStruct, allow_block: AllowBlock) -> Result<Expr> { |
| 1108 | assign_expr(input, allow_struct, allow_block) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1109 | } |
| 1110 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1111 | #[cfg(not(feature = "full"))] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1112 | fn ambiguous_expr(input: ParseStream, allow_struct: AllowStruct, allow_block: AllowBlock) -> Result<Expr> { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1113 | // NOTE: We intentionally skip assign_expr, placement_expr, and |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1114 | // range_expr as they are only parsed in full mode. |
| 1115 | or_expr(input, allow_struct, allow_block) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1116 | } |
| 1117 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1118 | // Parse a left-associative binary operator. |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1119 | macro_rules! binop { |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1120 | ($name:ident, $next:ident, |$var:ident| $parse_op:expr) => { |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1121 | fn $name(input: ParseStream, allow_struct: AllowStruct, allow_block: AllowBlock) -> Result<Expr> { |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1122 | let $var = input; |
| 1123 | let mut e: Expr = $next(input, allow_struct, allow_block)?; |
| 1124 | while let Some(op) = $parse_op { |
| 1125 | e = Expr::Binary(ExprBinary { |
| 1126 | attrs: Vec::new(), |
| 1127 | left: Box::new(e), |
| 1128 | op: op, |
| 1129 | right: Box::new($next(input, allow_struct, AllowBlock(true))?), |
| 1130 | }); |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1131 | } |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1132 | Ok(e) |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1133 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1134 | } |
David Tolnay | 54e854d | 2016-10-24 12:03:30 -0700 | [diff] [blame] | 1135 | } |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 1136 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1137 | // <placement> = <placement> .. |
| 1138 | // <placement> += <placement> .. |
| 1139 | // <placement> -= <placement> .. |
| 1140 | // <placement> *= <placement> .. |
| 1141 | // <placement> /= <placement> .. |
| 1142 | // <placement> %= <placement> .. |
| 1143 | // <placement> ^= <placement> .. |
| 1144 | // <placement> &= <placement> .. |
| 1145 | // <placement> |= <placement> .. |
| 1146 | // <placement> <<= <placement> .. |
| 1147 | // <placement> >>= <placement> .. |
| 1148 | // |
| 1149 | // NOTE: This operator is right-associative. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1150 | #[cfg(feature = "full")] |
David Tolnay | 1d2391c | 2018-08-27 10:29:28 -0700 | [diff] [blame] | 1151 | fn assign_expr(input: ParseStream, allow_struct: AllowStruct, allow_block: AllowBlock) -> Result<Expr> { |
| 1152 | let mut e = placement_expr(input, allow_struct, allow_block)?; |
| 1153 | if input.peek(Token![=]) && !input.peek(Token![==]) && !input.peek(Token![=>]) { |
| 1154 | e = Expr::Assign(ExprAssign { |
| 1155 | attrs: Vec::new(), |
| 1156 | left: Box::new(e), |
| 1157 | eq_token: input.parse()?, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1158 | // Recurse into self to parse right-associative operator. |
David Tolnay | 1d2391c | 2018-08-27 10:29:28 -0700 | [diff] [blame] | 1159 | right: Box::new(assign_expr(input, allow_struct, AllowBlock(true))?), |
| 1160 | }); |
| 1161 | } else if input.peek(Token![+=]) |
| 1162 | || input.peek(Token![-=]) |
| 1163 | || input.peek(Token![*=]) |
| 1164 | || input.peek(Token![/=]) |
| 1165 | || input.peek(Token![%=]) |
| 1166 | || input.peek(Token![^=]) |
| 1167 | || input.peek(Token![&=]) |
| 1168 | || input.peek(Token![|=]) |
| 1169 | || input.peek(Token![<<=]) |
| 1170 | || input.peek(Token![>>=]) |
| 1171 | { |
| 1172 | e = Expr::AssignOp(ExprAssignOp { |
| 1173 | attrs: Vec::new(), |
| 1174 | left: Box::new(e), |
| 1175 | op: BinOp::parse_assign_op(input)?, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1176 | // Recurse into self to parse right-associative operator. |
David Tolnay | 1d2391c | 2018-08-27 10:29:28 -0700 | [diff] [blame] | 1177 | right: Box::new(assign_expr(input, allow_struct, AllowBlock(true))?), |
| 1178 | }); |
| 1179 | } |
| 1180 | Ok(e) |
| 1181 | } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1182 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1183 | // <range> <- <range> .. |
| 1184 | // |
| 1185 | // NOTE: The `in place { expr }` version of this syntax is parsed in |
| 1186 | // `atom_expr`, not here. |
| 1187 | // |
| 1188 | // NOTE: This operator is right-associative. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1189 | #[cfg(feature = "full")] |
David Tolnay | 1da8c21 | 2018-08-27 10:35:50 -0700 | [diff] [blame^] | 1190 | fn placement_expr(input: ParseStream, allow_struct: AllowStruct, allow_block: AllowBlock) -> Result<Expr> { |
| 1191 | let mut e = range_expr(input, allow_struct, allow_block)?; |
| 1192 | if input.peek(Token![<-]) { |
| 1193 | e = Expr::InPlace(ExprInPlace { |
| 1194 | attrs: Vec::new(), |
| 1195 | place: Box::new(e), |
| 1196 | arrow_token: input.parse()?, |
| 1197 | value: Box::new(placement_expr(input, allow_struct, AllowBlock(true))?), |
| 1198 | }); |
| 1199 | } |
| 1200 | Ok(e) |
| 1201 | } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1202 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1203 | // <or> ... <or> .. |
| 1204 | // <or> .. <or> .. |
| 1205 | // <or> .. |
| 1206 | // |
| 1207 | // NOTE: This is currently parsed oddly - I'm not sure of what the exact |
| 1208 | // rules are for parsing these expressions are, but this is not correct. |
| 1209 | // For example, `a .. b .. c` is not a legal expression. It should not |
| 1210 | // be parsed as either `(a .. b) .. c` or `a .. (b .. c)` apparently. |
| 1211 | // |
| 1212 | // NOTE: The form of ranges which don't include a preceding expression are |
| 1213 | // parsed by `atom_expr`, rather than by this function. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1214 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1215 | named2!(range_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, do_parse!( |
| 1216 | mut e: shim!(or_expr, allow_struct, allow_block) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1217 | many0!(do_parse!( |
| 1218 | limits: syn!(RangeLimits) >> |
| 1219 | // We don't want to allow blocks here if we don't allow structs. See |
| 1220 | // the reasoning for `opt_ambiguous_expr!` above. |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1221 | hi: option!(shim!(or_expr, allow_struct, AllowBlock(allow_struct.0))) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1222 | ({ |
| 1223 | e = ExprRange { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1224 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1225 | from: Some(Box::new(e)), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1226 | limits: limits, |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1227 | to: hi.map(|e| Box::new(e)), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1228 | }.into(); |
| 1229 | }) |
| 1230 | )) >> |
| 1231 | (e) |
| 1232 | )); |
| 1233 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1234 | // <and> || <and> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1235 | binop!(or_expr, and_expr, |input| { |
| 1236 | if input.peek(Token![||]) { |
| 1237 | Some(BinOp::Or(input.parse()?)) |
| 1238 | } else { |
| 1239 | None |
| 1240 | } |
| 1241 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1242 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1243 | // <compare> && <compare> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1244 | binop!(and_expr, compare_expr, |input| { |
| 1245 | if input.peek(Token![&&]) { |
| 1246 | Some(BinOp::And(input.parse()?)) |
| 1247 | } else { |
| 1248 | None |
| 1249 | } |
| 1250 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1251 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1252 | // <bitor> == <bitor> ... |
| 1253 | // <bitor> != <bitor> ... |
| 1254 | // <bitor> >= <bitor> ... |
| 1255 | // <bitor> <= <bitor> ... |
| 1256 | // <bitor> > <bitor> ... |
| 1257 | // <bitor> < <bitor> ... |
| 1258 | // |
| 1259 | // NOTE: This operator appears to be parsed as left-associative, but errors |
| 1260 | // if it is used in a non-associative manner. |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1261 | binop!(compare_expr, bitor_expr, |input| { |
| 1262 | if input.peek(Token![==]) { |
| 1263 | Some(BinOp::Eq(input.parse()?)) |
| 1264 | } else if input.peek(Token![!=]) { |
| 1265 | Some(BinOp::Ne(input.parse()?)) |
| 1266 | // must be before `<` |
| 1267 | } else if input.peek(Token![<=]) { |
| 1268 | Some(BinOp::Le(input.parse()?)) |
| 1269 | // must be before `>` |
| 1270 | } else if input.peek(Token![>=]) { |
| 1271 | Some(BinOp::Ge(input.parse()?)) |
| 1272 | } else if input.peek(Token![<]) && !input.peek(Token![<<]) && !input.peek(Token![<-]) { |
| 1273 | Some(BinOp::Lt(input.parse()?)) |
| 1274 | } else if input.peek(Token![>]) && !input.peek(Token![>>]) { |
| 1275 | Some(BinOp::Gt(input.parse()?)) |
| 1276 | } else { |
| 1277 | None |
| 1278 | } |
| 1279 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1280 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1281 | // <bitxor> | <bitxor> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1282 | binop!(bitor_expr, bitxor_expr, |input| { |
| 1283 | if input.peek(Token![|]) && !input.peek(Token![||]) && !input.peek(Token![|=]) { |
| 1284 | Some(BinOp::BitOr(input.parse()?)) |
| 1285 | } else { |
| 1286 | None |
| 1287 | } |
| 1288 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1289 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1290 | // <bitand> ^ <bitand> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1291 | binop!(bitxor_expr, bitand_expr, |input| { |
| 1292 | if input.peek(Token![^]) && !input.peek(Token![^=]) { |
| 1293 | Some(BinOp::BitXor(input.parse()?)) |
| 1294 | } else { |
| 1295 | None |
| 1296 | } |
| 1297 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1298 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1299 | // <shift> & <shift> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1300 | binop!(bitand_expr, shift_expr, |input| { |
| 1301 | if input.peek(Token![&]) && !input.peek(Token![&&]) && !input.peek(Token![&=]) { |
| 1302 | Some(BinOp::BitAnd(input.parse()?)) |
| 1303 | } else { |
| 1304 | None |
| 1305 | } |
| 1306 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1307 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1308 | // <arith> << <arith> ... |
| 1309 | // <arith> >> <arith> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1310 | binop!(shift_expr, arith_expr, |input| { |
| 1311 | if input.peek(Token![<<]) && !input.peek(Token![<<=]) { |
| 1312 | Some(BinOp::Shl(input.parse()?)) |
| 1313 | } else if input.peek(Token![>>]) && !input.peek(Token![>>=]) { |
| 1314 | Some(BinOp::Shr(input.parse()?)) |
| 1315 | } else { |
| 1316 | None |
| 1317 | } |
| 1318 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1319 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1320 | // <term> + <term> ... |
| 1321 | // <term> - <term> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1322 | binop!(arith_expr, term_expr, |input| { |
| 1323 | if input.peek(Token![+]) && !input.peek(Token![+=]) { |
| 1324 | Some(BinOp::Add(input.parse()?)) |
| 1325 | } else if input.peek(Token![-]) && !input.peek(Token![-=]) { |
| 1326 | Some(BinOp::Sub(input.parse()?)) |
| 1327 | } else { |
| 1328 | None |
| 1329 | } |
| 1330 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1331 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1332 | // <cast> * <cast> ... |
| 1333 | // <cast> / <cast> ... |
| 1334 | // <cast> % <cast> ... |
David Tolnay | 378175c | 2018-08-27 10:01:12 -0700 | [diff] [blame] | 1335 | binop!(term_expr, cast_expr, |input| { |
| 1336 | if input.peek(Token![*]) && !input.peek(Token![*=]) { |
| 1337 | Some(BinOp::Mul(input.parse()?)) |
| 1338 | } else if input.peek(Token![/]) && !input.peek(Token![/=]) { |
| 1339 | Some(BinOp::Div(input.parse()?)) |
| 1340 | } else if input.peek(Token![%]) && !input.peek(Token![%=]) { |
| 1341 | Some(BinOp::Rem(input.parse()?)) |
| 1342 | } else { |
| 1343 | None |
| 1344 | } |
| 1345 | }); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1346 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1347 | // <unary> as <ty> |
| 1348 | // <unary> : <ty> |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 1349 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1350 | named2!(cast_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, do_parse!( |
| 1351 | mut e: shim!(unary_expr, allow_struct, allow_block) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1352 | many0!(alt!( |
| 1353 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1354 | as_: keyword!(as) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1355 | // We can't accept `A + B` in cast expressions, as it's |
| 1356 | // ambiguous with the + expression. |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 1357 | ty: shim!(Type::without_plus) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1358 | ({ |
| 1359 | e = ExprCast { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1360 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1361 | expr: Box::new(e), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1362 | as_token: as_, |
| 1363 | ty: Box::new(ty), |
| 1364 | }.into(); |
| 1365 | }) |
| 1366 | ) |
| 1367 | | |
| 1368 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1369 | colon: punct!(:) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1370 | // We can't accept `A + B` in cast expressions, as it's |
| 1371 | // ambiguous with the + expression. |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 1372 | ty: shim!(Type::without_plus) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1373 | ({ |
| 1374 | e = ExprType { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1375 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1376 | expr: Box::new(e), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1377 | colon_token: colon, |
| 1378 | ty: Box::new(ty), |
| 1379 | }.into(); |
| 1380 | }) |
| 1381 | ) |
| 1382 | )) >> |
| 1383 | (e) |
| 1384 | )); |
| 1385 | |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 1386 | // <unary> as <ty> |
| 1387 | #[cfg(not(feature = "full"))] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1388 | named2!(cast_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, do_parse!( |
| 1389 | mut e: shim!(unary_expr, allow_struct, allow_block) >> |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 1390 | many0!(do_parse!( |
| 1391 | as_: keyword!(as) >> |
| 1392 | // We can't accept `A + B` in cast expressions, as it's |
| 1393 | // ambiguous with the + expression. |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 1394 | ty: shim!(Type::without_plus) >> |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 1395 | ({ |
| 1396 | e = ExprCast { |
| 1397 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1398 | expr: Box::new(e), |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 1399 | as_token: as_, |
| 1400 | ty: Box::new(ty), |
| 1401 | }.into(); |
| 1402 | }) |
| 1403 | )) >> |
| 1404 | (e) |
| 1405 | )); |
| 1406 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1407 | // <UnOp> <trailer> |
| 1408 | // & <trailer> |
| 1409 | // &mut <trailer> |
| 1410 | // box <trailer> |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1411 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1412 | named2!(unary_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, alt!( |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1413 | do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1414 | attrs: many0!(Attribute::old_parse_outer) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1415 | op: syn!(UnOp) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1416 | expr: shim!(unary_expr, allow_struct, AllowBlock(true)) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1417 | (ExprUnary { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1418 | attrs: attrs, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1419 | op: op, |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1420 | expr: Box::new(expr), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1421 | }.into()) |
| 1422 | ) |
| 1423 | | |
| 1424 | do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1425 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1426 | and: punct!(&) >> |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 1427 | mutability: option!(keyword!(mut)) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1428 | expr: shim!(unary_expr, allow_struct, AllowBlock(true)) >> |
David Tolnay | 00674ba | 2018-03-31 18:14:11 +0200 | [diff] [blame] | 1429 | (ExprReference { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1430 | attrs: attrs, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1431 | and_token: and, |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 1432 | mutability: mutability, |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1433 | expr: Box::new(expr), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1434 | }.into()) |
| 1435 | ) |
| 1436 | | |
| 1437 | do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1438 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1439 | box_: keyword!(box) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1440 | expr: shim!(unary_expr, allow_struct, AllowBlock(true)) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1441 | (ExprBox { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1442 | attrs: attrs, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1443 | box_token: box_, |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1444 | expr: Box::new(expr), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1445 | }.into()) |
| 1446 | ) |
| 1447 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1448 | shim!(trailer_expr, allow_struct, allow_block) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1449 | )); |
| 1450 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1451 | // XXX: This duplication is ugly |
| 1452 | #[cfg(not(feature = "full"))] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1453 | named2!(unary_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, alt!( |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1454 | do_parse!( |
| 1455 | op: syn!(UnOp) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1456 | expr: shim!(unary_expr, allow_struct, AllowBlock(true)) >> |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1457 | (ExprUnary { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1458 | attrs: Vec::new(), |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1459 | op: op, |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1460 | expr: Box::new(expr), |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1461 | }.into()) |
| 1462 | ) |
| 1463 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1464 | shim!(trailer_expr, allow_struct, allow_block) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1465 | )); |
| 1466 | |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 1467 | #[cfg(feature = "full")] |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1468 | fn take_outer(attrs: &mut Vec<Attribute>) -> Vec<Attribute> { |
| 1469 | let mut outer = Vec::new(); |
| 1470 | let mut inner = Vec::new(); |
| 1471 | for attr in mem::replace(attrs, Vec::new()) { |
| 1472 | match attr.style { |
| 1473 | AttrStyle::Outer => outer.push(attr), |
| 1474 | AttrStyle::Inner(_) => inner.push(attr), |
| 1475 | } |
| 1476 | } |
| 1477 | *attrs = inner; |
| 1478 | outer |
| 1479 | } |
| 1480 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1481 | // <atom> (..<args>) ... |
| 1482 | // <atom> . <ident> (..<args>) ... |
| 1483 | // <atom> . <ident> ... |
| 1484 | // <atom> . <lit> ... |
| 1485 | // <atom> [ <expr> ] ... |
| 1486 | // <atom> ? ... |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1487 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1488 | named2!(trailer_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, do_parse!( |
| 1489 | mut e: shim!(atom_expr, allow_struct, allow_block) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1490 | outer_attrs: value!({ |
| 1491 | let mut attrs = e.replace_attrs(Vec::new()); |
| 1492 | let outer_attrs = take_outer(&mut attrs); |
| 1493 | e.replace_attrs(attrs); |
| 1494 | outer_attrs |
| 1495 | }) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1496 | many0!(alt!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1497 | tap!(args: shim!(and_call) => { |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1498 | let (paren, args) = args; |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1499 | e = ExprCall { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1500 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1501 | func: Box::new(e), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1502 | args: args, |
| 1503 | paren_token: paren, |
| 1504 | }.into(); |
| 1505 | }) |
| 1506 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1507 | tap!(more: shim!(and_method_call) => { |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1508 | let mut call = more; |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1509 | call.receiver = Box::new(e); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1510 | e = call.into(); |
| 1511 | }) |
| 1512 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1513 | tap!(field: shim!(and_field) => { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1514 | let (token, member) = field; |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1515 | e = ExprField { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1516 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1517 | base: Box::new(e), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1518 | dot_token: token, |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1519 | member: member, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1520 | }.into(); |
| 1521 | }) |
| 1522 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1523 | tap!(i: shim!(and_index) => { |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1524 | let (bracket, i) = i; |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1525 | e = ExprIndex { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1526 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1527 | expr: Box::new(e), |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1528 | bracket_token: bracket, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1529 | index: Box::new(i), |
| 1530 | }.into(); |
| 1531 | }) |
| 1532 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1533 | tap!(question: punct!(?) => { |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1534 | e = ExprTry { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1535 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1536 | expr: Box::new(e), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1537 | question_token: question, |
| 1538 | }.into(); |
| 1539 | }) |
| 1540 | )) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1541 | ({ |
| 1542 | let mut attrs = outer_attrs; |
| 1543 | attrs.extend(e.replace_attrs(Vec::new())); |
| 1544 | e.replace_attrs(attrs); |
| 1545 | e |
| 1546 | }) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1547 | )); |
| 1548 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1549 | // XXX: Duplication == ugly |
| 1550 | #[cfg(not(feature = "full"))] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1551 | named2!(trailer_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, do_parse!( |
| 1552 | mut e: shim!(atom_expr, allow_struct, allow_block) >> |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1553 | many0!(alt!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1554 | tap!(args: shim!(and_call) => { |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1555 | e = ExprCall { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1556 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1557 | func: Box::new(e), |
David Tolnay | e3d41b7 | 2017-12-31 15:24:00 -0500 | [diff] [blame] | 1558 | paren_token: args.0, |
| 1559 | args: args.1, |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1560 | }.into(); |
| 1561 | }) |
| 1562 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1563 | tap!(field: shim!(and_field) => { |
David Tolnay | d514774 | 2018-06-30 10:09:52 -0700 | [diff] [blame] | 1564 | let (token, member) = field; |
| 1565 | e = ExprField { |
| 1566 | attrs: Vec::new(), |
| 1567 | base: Box::new(e), |
| 1568 | dot_token: token, |
| 1569 | member: member, |
| 1570 | }.into(); |
| 1571 | }) |
| 1572 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1573 | tap!(i: shim!(and_index) => { |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1574 | e = ExprIndex { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1575 | attrs: Vec::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1576 | expr: Box::new(e), |
David Tolnay | e3d41b7 | 2017-12-31 15:24:00 -0500 | [diff] [blame] | 1577 | bracket_token: i.0, |
| 1578 | index: Box::new(i.1), |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1579 | }.into(); |
| 1580 | }) |
| 1581 | )) >> |
| 1582 | (e) |
| 1583 | )); |
| 1584 | |
David Tolnay | a454c8f | 2018-01-07 01:01:10 -0800 | [diff] [blame] | 1585 | // Parse all atomic expressions which don't have to worry about precedence |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1586 | // interactions, as they are fully contained. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1587 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1588 | named2!(atom_expr(allow_struct: AllowStruct, allow_block: AllowBlock) -> Expr, alt!( |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1589 | syn!(ExprGroup) => { Expr::Group } // must be placed first |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1590 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1591 | syn!(ExprLit) => { Expr::Lit } // must be before expr_struct |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1592 | | |
Yusuke Sasaki | 851062f | 2018-08-01 06:28:28 +0900 | [diff] [blame] | 1593 | // must be before ExprStruct |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 1594 | syn!(ExprAsync) => { Expr::Async } |
Yusuke Sasaki | 851062f | 2018-08-01 06:28:28 +0900 | [diff] [blame] | 1595 | | |
David Tolnay | f717705 | 2018-08-24 15:31:50 -0400 | [diff] [blame] | 1596 | // must be before ExprStruct |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 1597 | syn!(ExprTryBlock) => { Expr::TryBlock } |
David Tolnay | f717705 | 2018-08-24 15:31:50 -0400 | [diff] [blame] | 1598 | | |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1599 | // must be before expr_path |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1600 | cond_reduce!(allow_struct.0, syn!(ExprStruct)) => { Expr::Struct } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1601 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1602 | syn!(ExprParen) => { Expr::Paren } // must be before expr_tup |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1603 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1604 | syn!(ExprMacro) => { Expr::Macro } // must be before expr_path |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1605 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1606 | shim!(expr_break, allow_struct) // must be before expr_path |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1607 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1608 | syn!(ExprContinue) => { Expr::Continue } // must be before expr_path |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1609 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1610 | shim!(expr_ret, allow_struct) // must be before expr_path |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1611 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1612 | syn!(ExprArray) => { Expr::Array } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1613 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1614 | syn!(ExprTuple) => { Expr::Tuple } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1615 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1616 | syn!(ExprIf) => { Expr::If } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1617 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1618 | syn!(ExprIfLet) => { Expr::IfLet } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1619 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1620 | syn!(ExprWhile) => { Expr::While } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1621 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1622 | syn!(ExprWhileLet) => { Expr::WhileLet } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1623 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1624 | syn!(ExprForLoop) => { Expr::ForLoop } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1625 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1626 | syn!(ExprLoop) => { Expr::Loop } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1627 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1628 | syn!(ExprMatch) => { Expr::Match } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1629 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1630 | syn!(ExprYield) => { Expr::Yield } |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 1631 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1632 | syn!(ExprUnsafe) => { Expr::Unsafe } |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 1633 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1634 | shim!(expr_closure, allow_struct) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1635 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1636 | cond_reduce!(allow_block.0, syn!(ExprBlock)) => { Expr::Block } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1637 | | |
| 1638 | // NOTE: This is the prefix-form of range |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1639 | shim!(expr_range, allow_struct) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1640 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1641 | syn!(ExprPath) => { Expr::Path } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1642 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1643 | syn!(ExprRepeat) => { Expr::Repeat } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1644 | )); |
| 1645 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1646 | #[cfg(not(feature = "full"))] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1647 | named2!(atom_expr(_allow_struct: AllowStruct, _allow_block: AllowBlock) -> Expr, alt!( |
David Tolnay | e98775f | 2017-12-28 23:17:00 -0500 | [diff] [blame] | 1648 | syn!(ExprLit) => { Expr::Lit } |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1649 | | |
David Tolnay | 9374bc0 | 2018-01-27 18:49:36 -0800 | [diff] [blame] | 1650 | syn!(ExprParen) => { Expr::Paren } |
| 1651 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1652 | syn!(ExprPath) => { Expr::Path } |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1653 | )); |
| 1654 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1655 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1656 | named2!(expr_nosemi -> Expr, do_parse!( |
David Tolnay | 313a36f | 2018-04-29 20:13:04 -0700 | [diff] [blame] | 1657 | nosemi: alt!( |
| 1658 | syn!(ExprIf) => { Expr::If } |
| 1659 | | |
| 1660 | syn!(ExprIfLet) => { Expr::IfLet } |
| 1661 | | |
| 1662 | syn!(ExprWhile) => { Expr::While } |
| 1663 | | |
| 1664 | syn!(ExprWhileLet) => { Expr::WhileLet } |
| 1665 | | |
| 1666 | syn!(ExprForLoop) => { Expr::ForLoop } |
| 1667 | | |
| 1668 | syn!(ExprLoop) => { Expr::Loop } |
| 1669 | | |
| 1670 | syn!(ExprMatch) => { Expr::Match } |
| 1671 | | |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 1672 | syn!(ExprTryBlock) => { Expr::TryBlock } |
David Tolnay | 313a36f | 2018-04-29 20:13:04 -0700 | [diff] [blame] | 1673 | | |
| 1674 | syn!(ExprYield) => { Expr::Yield } |
| 1675 | | |
| 1676 | syn!(ExprUnsafe) => { Expr::Unsafe } |
| 1677 | | |
| 1678 | syn!(ExprBlock) => { Expr::Block } |
| 1679 | ) >> |
| 1680 | // If the next token is a `.` or a `?` it is special-cased to parse |
| 1681 | // as an expression instead of a blockexpression. |
| 1682 | not!(punct!(.)) >> |
| 1683 | not!(punct!(?)) >> |
David Tolnay | 83ddebb | 2018-05-05 00:29:13 -0700 | [diff] [blame] | 1684 | (nosemi) |
David Tolnay | 313a36f | 2018-04-29 20:13:04 -0700 | [diff] [blame] | 1685 | )); |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1686 | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1687 | impl Synom for ExprLit { |
David Tolnay | eb981bb | 2018-07-21 19:31:38 -0700 | [diff] [blame] | 1688 | #[cfg(not(feature = "full"))] |
| 1689 | named!(parse -> Self, do_parse!( |
| 1690 | lit: syn!(Lit) >> |
| 1691 | (ExprLit { |
| 1692 | attrs: Vec::new(), |
| 1693 | lit: lit, |
| 1694 | }) |
| 1695 | )); |
| 1696 | |
| 1697 | #[cfg(feature = "full")] |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1698 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1699 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1700 | lit: syn!(Lit) >> |
| 1701 | (ExprLit { |
David Tolnay | 73c9b52 | 2018-07-21 15:58:40 -0700 | [diff] [blame] | 1702 | attrs: attrs, |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1703 | lit: lit, |
| 1704 | }) |
| 1705 | )); |
| 1706 | } |
| 1707 | |
| 1708 | #[cfg(feature = "full")] |
| 1709 | impl Synom for ExprMacro { |
| 1710 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1711 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1712 | mac: syn!(Macro) >> |
| 1713 | (ExprMacro { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1714 | attrs: attrs, |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1715 | mac: mac, |
| 1716 | }) |
| 1717 | )); |
| 1718 | } |
| 1719 | |
David Tolnay | e98775f | 2017-12-28 23:17:00 -0500 | [diff] [blame] | 1720 | #[cfg(feature = "full")] |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1721 | impl Synom for ExprGroup { |
| 1722 | named!(parse -> Self, do_parse!( |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 1723 | e: old_grouped!(syn!(Expr)) >> |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1724 | (ExprGroup { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1725 | attrs: Vec::new(), |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1726 | expr: Box::new(e.1), |
| 1727 | group_token: e.0, |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 1728 | }) |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1729 | )); |
| 1730 | } |
| 1731 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1732 | impl Synom for ExprParen { |
David Tolnay | eb981bb | 2018-07-21 19:31:38 -0700 | [diff] [blame] | 1733 | #[cfg(not(feature = "full"))] |
| 1734 | named!(parse -> Self, do_parse!( |
| 1735 | e: parens!(syn!(Expr)) >> |
| 1736 | (ExprParen { |
| 1737 | attrs: Vec::new(), |
| 1738 | paren_token: e.0, |
| 1739 | expr: Box::new(e.1), |
| 1740 | }) |
| 1741 | )); |
| 1742 | |
| 1743 | #[cfg(feature = "full")] |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1744 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1745 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1746 | e: parens!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1747 | many0!(Attribute::old_parse_inner), |
David Tolnay | 0235ba6 | 2018-07-21 19:20:50 -0700 | [diff] [blame] | 1748 | syn!(Expr), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1749 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1750 | (ExprParen { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1751 | attrs: { |
| 1752 | let mut attrs = outer_attrs; |
| 1753 | attrs.extend((e.1).0); |
| 1754 | attrs |
| 1755 | }, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1756 | paren_token: e.0, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1757 | expr: Box::new((e.1).1), |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 1758 | }) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1759 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1760 | } |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1761 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1762 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1763 | impl Synom for ExprArray { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1764 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1765 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1766 | elems: brackets!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1767 | many0!(Attribute::old_parse_inner), |
David Tolnay | 0235ba6 | 2018-07-21 19:20:50 -0700 | [diff] [blame] | 1768 | call!(Punctuated::parse_terminated), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1769 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1770 | (ExprArray { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1771 | attrs: { |
| 1772 | let mut attrs = outer_attrs; |
| 1773 | attrs.extend((elems.1).0); |
| 1774 | attrs |
| 1775 | }, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1776 | bracket_token: elems.0, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1777 | elems: (elems.1).1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1778 | }) |
| 1779 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1780 | } |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1781 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1782 | named2!(and_call -> (token::Paren, Punctuated<Expr, Token![,]>), |
David Tolnay | 76178be | 2018-07-31 23:06:15 -0700 | [diff] [blame] | 1783 | parens!(Punctuated::parse_terminated) |
| 1784 | ); |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1785 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1786 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1787 | named2!(and_method_call -> ExprMethodCall, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1788 | dot: punct!(.) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1789 | method: syn!(Ident) >> |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 1790 | turbofish: option!(tuple!( |
| 1791 | punct!(::), |
| 1792 | punct!(<), |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 1793 | call!(Punctuated::parse_terminated), |
David Tolnay | 0235ba6 | 2018-07-21 19:20:50 -0700 | [diff] [blame] | 1794 | punct!(>), |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1795 | )) >> |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 1796 | args: parens!(Punctuated::parse_terminated) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1797 | ({ |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1798 | ExprMethodCall { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1799 | attrs: Vec::new(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1800 | // this expr will get overwritten after being returned |
David Tolnay | 360efd2 | 2018-01-04 23:35:26 -0800 | [diff] [blame] | 1801 | receiver: Box::new(Expr::Verbatim(ExprVerbatim { |
hcpl | aa51179 | 2018-05-29 07:13:01 +0300 | [diff] [blame] | 1802 | tts: TokenStream::new(), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 1803 | })), |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1804 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1805 | method: method, |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 1806 | turbofish: turbofish.map(|fish| MethodTurbofish { |
| 1807 | colon2_token: fish.0, |
| 1808 | lt_token: fish.1, |
| 1809 | args: fish.2, |
| 1810 | gt_token: fish.3, |
| 1811 | }), |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1812 | args: args.1, |
| 1813 | paren_token: args.0, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1814 | dot_token: dot, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1815 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1816 | }) |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1817 | )); |
| 1818 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1819 | #[cfg(feature = "full")] |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 1820 | impl Synom for GenericMethodArgument { |
| 1821 | // TODO parse const generics as well |
| 1822 | named!(parse -> Self, map!(ty_no_eq_after, GenericMethodArgument::Type)); |
| 1823 | } |
| 1824 | |
| 1825 | #[cfg(feature = "full")] |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 1826 | impl Synom for ExprTuple { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1827 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1828 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1829 | elems: parens!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1830 | many0!(Attribute::old_parse_inner), |
David Tolnay | 0235ba6 | 2018-07-21 19:20:50 -0700 | [diff] [blame] | 1831 | call!(Punctuated::parse_terminated), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1832 | )) >> |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 1833 | (ExprTuple { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1834 | attrs: { |
| 1835 | let mut attrs = outer_attrs; |
| 1836 | attrs.extend((elems.1).0); |
| 1837 | attrs |
| 1838 | }, |
| 1839 | elems: (elems.1).1, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1840 | paren_token: elems.0, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1841 | }) |
| 1842 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1843 | } |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1844 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1845 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1846 | impl Synom for ExprIfLet { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1847 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1848 | if_: keyword!(if) >> |
| 1849 | let_: keyword!(let) >> |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 1850 | pats: call!(Punctuated::parse_separated_nonempty) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1851 | eq: punct!(=) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1852 | cond: shim!(expr_no_struct) >> |
| 1853 | then_block: braces!(Block::old_parse_within) >> |
| 1854 | else_block: option!(shim!(else_block)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1855 | (ExprIfLet { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1856 | attrs: Vec::new(), |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 1857 | pats: pats, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1858 | let_token: let_, |
| 1859 | eq_token: eq, |
| 1860 | expr: Box::new(cond), |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 1861 | then_branch: Block { |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1862 | brace_token: then_block.0, |
| 1863 | stmts: then_block.1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1864 | }, |
| 1865 | if_token: if_, |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 1866 | else_branch: else_block, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1867 | }) |
| 1868 | )); |
David Tolnay | 29f9ce1 | 2016-10-02 20:58:40 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1871 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1872 | impl Synom for ExprIf { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1873 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1874 | if_: keyword!(if) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1875 | cond: shim!(expr_no_struct) >> |
| 1876 | then_block: braces!(Block::old_parse_within) >> |
| 1877 | else_block: option!(shim!(else_block)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1878 | (ExprIf { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1879 | attrs: Vec::new(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1880 | cond: Box::new(cond), |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 1881 | then_branch: Block { |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1882 | brace_token: then_block.0, |
| 1883 | stmts: then_block.1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1884 | }, |
| 1885 | if_token: if_, |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 1886 | else_branch: else_block, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1887 | }) |
| 1888 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1889 | } |
David Tolnay | bb6feae | 2016-10-02 21:25:20 -0700 | [diff] [blame] | 1890 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1891 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1892 | named2!(else_block -> (Token![else], Box<Expr>), do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1893 | else_: keyword!(else) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1894 | expr: alt!( |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1895 | syn!(ExprIf) => { Expr::If } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1896 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1897 | syn!(ExprIfLet) => { Expr::IfLet } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1898 | | |
| 1899 | do_parse!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1900 | else_block: braces!(Block::old_parse_within) >> |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 1901 | (Expr::Block(ExprBlock { |
| 1902 | attrs: Vec::new(), |
David Tolnay | 1d8e996 | 2018-08-24 19:04:20 -0400 | [diff] [blame] | 1903 | label: None, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1904 | block: Block { |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1905 | brace_token: else_block.0, |
| 1906 | stmts: else_block.1, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1907 | }, |
| 1908 | })) |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1909 | ) |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1910 | ) >> |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 1911 | (else_, Box::new(expr)) |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1912 | )); |
| 1913 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1914 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1915 | impl Synom for ExprForLoop { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1916 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1917 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 1918 | label: option!(syn!(Label)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1919 | for_: keyword!(for) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1920 | pat: syn!(Pat) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1921 | in_: keyword!(in) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1922 | expr: shim!(expr_no_struct) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1923 | block: braces!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1924 | many0!(Attribute::old_parse_inner), |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1925 | shim!(Block::parse_within), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1926 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1927 | (ExprForLoop { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1928 | attrs: { |
| 1929 | let mut attrs = outer_attrs; |
| 1930 | attrs.extend((block.1).0); |
| 1931 | attrs |
| 1932 | }, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 1933 | label: label, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1934 | for_token: for_, |
| 1935 | pat: Box::new(pat), |
| 1936 | in_token: in_, |
| 1937 | expr: Box::new(expr), |
| 1938 | body: Block { |
| 1939 | brace_token: block.0, |
| 1940 | stmts: (block.1).1, |
| 1941 | }, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1942 | }) |
| 1943 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1944 | } |
Gregory Katz | e5f3568 | 2016-09-27 14:20:55 -0400 | [diff] [blame] | 1945 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1946 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1947 | impl Synom for ExprLoop { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1948 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1949 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 1950 | label: option!(syn!(Label)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1951 | loop_: keyword!(loop) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1952 | block: braces!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1953 | many0!(Attribute::old_parse_inner), |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1954 | shim!(Block::parse_within), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1955 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1956 | (ExprLoop { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1957 | attrs: { |
| 1958 | let mut attrs = outer_attrs; |
| 1959 | attrs.extend((block.1).0); |
| 1960 | attrs |
| 1961 | }, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 1962 | label: label, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1963 | loop_token: loop_, |
| 1964 | body: Block { |
| 1965 | brace_token: block.0, |
| 1966 | stmts: (block.1).1, |
| 1967 | }, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1968 | }) |
| 1969 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1972 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1973 | impl Synom for ExprMatch { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1974 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1975 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1976 | match_: keyword!(match) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 1977 | obj: shim!(expr_no_struct) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1978 | braced_content: braces!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 1979 | many0!(Attribute::old_parse_inner), |
David Tolnay | 0235ba6 | 2018-07-21 19:20:50 -0700 | [diff] [blame] | 1980 | many0!(syn!(Arm)), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1981 | )) >> |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1982 | (ExprMatch { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1983 | attrs: { |
| 1984 | let mut attrs = outer_attrs; |
| 1985 | attrs.extend((braced_content.1).0); |
| 1986 | attrs |
| 1987 | }, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 1988 | expr: Box::new(obj), |
| 1989 | match_token: match_, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 1990 | brace_token: braced_content.0, |
| 1991 | arms: (braced_content.1).1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1992 | }) |
| 1993 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1994 | } |
David Tolnay | 1978c67 | 2016-10-27 22:05:52 -0700 | [diff] [blame] | 1995 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1996 | #[cfg(feature = "full")] |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 1997 | impl Synom for ExprTryBlock { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1998 | named!(parse -> Self, do_parse!( |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 1999 | try_token: keyword!(try) >> |
| 2000 | block: syn!(Block) >> |
| 2001 | (ExprTryBlock { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2002 | attrs: Vec::new(), |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 2003 | try_token: try_token, |
| 2004 | block: block, |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 2005 | }) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2006 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2007 | } |
Arnavion | 02ef13f | 2017-04-25 00:54:31 -0700 | [diff] [blame] | 2008 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2009 | #[cfg(feature = "full")] |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 2010 | impl Synom for ExprYield { |
| 2011 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2012 | yield_: keyword!(yield) >> |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 2013 | expr: option!(syn!(Expr)) >> |
| 2014 | (ExprYield { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2015 | attrs: Vec::new(), |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 2016 | yield_token: yield_, |
| 2017 | expr: expr.map(Box::new), |
| 2018 | }) |
| 2019 | )); |
| 2020 | } |
| 2021 | |
| 2022 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2023 | impl Synom for Arm { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2024 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2025 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 18cc4d4 | 2018-03-31 18:47:20 +0200 | [diff] [blame] | 2026 | leading_vert: option!(punct!(|)) >> |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2027 | pats: call!(Punctuated::parse_separated_nonempty) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2028 | guard: option!(tuple!(keyword!(if), syn!(Expr))) >> |
David Tolnay | dfb9143 | 2018-03-31 19:19:44 +0200 | [diff] [blame] | 2029 | fat_arrow: punct!(=>) >> |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 2030 | body: do_parse!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2031 | expr: alt!(shim!(expr_nosemi) | syn!(Expr)) >> |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2032 | comma: switch!(value!(arm_expr_requires_comma(&expr)), |
| 2033 | true => alt!( |
| 2034 | input_end!() => { |_| None } |
| 2035 | | |
| 2036 | punct!(,) => { Some } |
| 2037 | ) |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 2038 | | |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2039 | false => option!(punct!(,)) |
| 2040 | ) >> |
| 2041 | (expr, comma) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2042 | ) >> |
| 2043 | (Arm { |
David Tolnay | dfb9143 | 2018-03-31 19:19:44 +0200 | [diff] [blame] | 2044 | fat_arrow_token: fat_arrow, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2045 | attrs: attrs, |
David Tolnay | 18cc4d4 | 2018-03-31 18:47:20 +0200 | [diff] [blame] | 2046 | leading_vert: leading_vert, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2047 | pats: pats, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 2048 | guard: guard.map(|(if_, guard)| (if_, Box::new(guard))), |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 2049 | body: Box::new(body.0), |
| 2050 | comma: body.1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2051 | }) |
| 2052 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2053 | } |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2054 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2055 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2056 | named2!(expr_closure(allow_struct: AllowStruct) -> Expr, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2057 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 7a008ff | 2018-07-31 22:52:56 -0700 | [diff] [blame] | 2058 | asyncness: option!(keyword!(async)) >> |
| 2059 | movability: option!(cond_reduce!(asyncness.is_none(), keyword!(static))) >> |
David Tolnay | efc96fb | 2017-12-29 02:03:15 -0500 | [diff] [blame] | 2060 | capture: option!(keyword!(move)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2061 | or1: punct!(|) >> |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2062 | inputs: call!(Punctuated::parse_terminated_with, fn_arg) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2063 | or2: punct!(|) >> |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 2064 | ret_and_body: alt!( |
| 2065 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2066 | arrow: punct!(->) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 2067 | ty: syn!(Type) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2068 | body: syn!(Block) >> |
David Tolnay | 76178be | 2018-07-31 23:06:15 -0700 | [diff] [blame] | 2069 | ( |
| 2070 | ReturnType::Type(arrow, Box::new(ty)), |
| 2071 | Expr::Block(ExprBlock { |
| 2072 | attrs: Vec::new(), |
David Tolnay | 1d8e996 | 2018-08-24 19:04:20 -0400 | [diff] [blame] | 2073 | label: None, |
David Tolnay | 76178be | 2018-07-31 23:06:15 -0700 | [diff] [blame] | 2074 | block: body, |
| 2075 | }, |
| 2076 | )) |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 2077 | ) |
| 2078 | | |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 2079 | map!(ambiguous_expr!(allow_struct), |e| (ReturnType::Default, e)) |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 2080 | ) >> |
Yusuke Sasaki | 4e5d966 | 2018-07-21 02:49:47 +0900 | [diff] [blame] | 2081 | (Expr::Closure(ExprClosure { |
| 2082 | attrs: attrs, |
| 2083 | asyncness: asyncness, |
| 2084 | movability: movability, |
| 2085 | capture: capture, |
| 2086 | or1_token: or1, |
| 2087 | inputs: inputs, |
| 2088 | or2_token: or2, |
| 2089 | output: ret_and_body.0, |
| 2090 | body: Box::new(ret_and_body.1), |
| 2091 | })) |
Yusuke Sasaki | 2dec315 | 2018-07-31 20:41:50 +0900 | [diff] [blame] | 2092 | )); |
| 2093 | |
| 2094 | #[cfg(feature = "full")] |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 2095 | impl Synom for ExprAsync { |
| 2096 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2097 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 2098 | async_token: keyword!(async) >> |
| 2099 | capture: option!(keyword!(move)) >> |
| 2100 | block: syn!(Block) >> |
| 2101 | (ExprAsync { |
| 2102 | attrs: attrs, |
| 2103 | async_token: async_token, |
| 2104 | capture: capture, |
| 2105 | block: block, |
| 2106 | }) |
| 2107 | )); |
| 2108 | } |
Yusuke Sasaki | 851062f | 2018-08-01 06:28:28 +0900 | [diff] [blame] | 2109 | |
| 2110 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2111 | named!(fn_arg -> FnArg, do_parse!( |
| 2112 | pat: syn!(Pat) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 2113 | ty: option!(tuple!(punct!(:), syn!(Type))) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2114 | ({ |
David Tolnay | 80ed55f | 2017-12-27 22:54:40 -0500 | [diff] [blame] | 2115 | if let Some((colon, ty)) = ty { |
| 2116 | FnArg::Captured(ArgCaptured { |
| 2117 | pat: pat, |
| 2118 | colon_token: colon, |
| 2119 | ty: ty, |
| 2120 | }) |
| 2121 | } else { |
| 2122 | FnArg::Inferred(pat) |
| 2123 | } |
David Tolnay | bb6feae | 2016-10-02 21:25:20 -0700 | [diff] [blame] | 2124 | }) |
Gregory Katz | 3e562cc | 2016-09-28 18:33:02 -0400 | [diff] [blame] | 2125 | )); |
| 2126 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2127 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2128 | impl Synom for ExprWhile { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2129 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2130 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2131 | label: option!(syn!(Label)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2132 | while_: keyword!(while) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2133 | cond: shim!(expr_no_struct) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2134 | block: braces!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2135 | many0!(Attribute::old_parse_inner), |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2136 | shim!(Block::parse_within), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2137 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2138 | (ExprWhile { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2139 | attrs: { |
| 2140 | let mut attrs = outer_attrs; |
| 2141 | attrs.extend((block.1).0); |
| 2142 | attrs |
| 2143 | }, |
| 2144 | label: label, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2145 | while_token: while_, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2146 | cond: Box::new(cond), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2147 | body: Block { |
| 2148 | brace_token: block.0, |
| 2149 | stmts: (block.1).1, |
| 2150 | }, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2151 | }) |
| 2152 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2155 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2156 | impl Synom for ExprWhileLet { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2157 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2158 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2159 | label: option!(syn!(Label)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2160 | while_: keyword!(while) >> |
| 2161 | let_: keyword!(let) >> |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 2162 | pats: call!(Punctuated::parse_separated_nonempty) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2163 | eq: punct!(=) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2164 | value: shim!(expr_no_struct) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2165 | block: braces!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2166 | many0!(Attribute::old_parse_inner), |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2167 | shim!(Block::parse_within), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2168 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2169 | (ExprWhileLet { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2170 | attrs: { |
| 2171 | let mut attrs = outer_attrs; |
| 2172 | attrs.extend((block.1).0); |
| 2173 | attrs |
| 2174 | }, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2175 | label: label, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2176 | while_token: while_, |
| 2177 | let_token: let_, |
| 2178 | pats: pats, |
| 2179 | eq_token: eq, |
| 2180 | expr: Box::new(value), |
| 2181 | body: Block { |
| 2182 | brace_token: block.0, |
| 2183 | stmts: (block.1).1, |
| 2184 | }, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2185 | }) |
| 2186 | )); |
| 2187 | } |
| 2188 | |
| 2189 | #[cfg(feature = "full")] |
| 2190 | impl Synom for Label { |
| 2191 | named!(parse -> Self, do_parse!( |
| 2192 | name: syn!(Lifetime) >> |
| 2193 | colon: punct!(:) >> |
| 2194 | (Label { |
| 2195 | name: name, |
| 2196 | colon_token: colon, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2197 | }) |
| 2198 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2201 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2202 | impl Synom for ExprContinue { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2203 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2204 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2205 | cont: keyword!(continue) >> |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2206 | label: option!(syn!(Lifetime)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2207 | (ExprContinue { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2208 | attrs: attrs, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2209 | continue_token: cont, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2210 | label: label, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2211 | }) |
| 2212 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2213 | } |
Gregory Katz | fd6935d | 2016-09-30 22:51:25 -0400 | [diff] [blame] | 2214 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2215 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2216 | named2!(expr_break(allow_struct: AllowStruct) -> Expr, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2217 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2218 | break_: keyword!(break) >> |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2219 | label: option!(syn!(Lifetime)) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 2220 | // We can't allow blocks after a `break` expression when we wouldn't |
| 2221 | // allow structs, as this expression is ambiguous. |
| 2222 | val: opt_ambiguous_expr!(allow_struct) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2223 | (ExprBreak { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2224 | attrs: attrs, |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 2225 | label: label, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2226 | expr: val.map(Box::new), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2227 | break_token: break_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2228 | }.into()) |
Gregory Katz | fd6935d | 2016-09-30 22:51:25 -0400 | [diff] [blame] | 2229 | )); |
| 2230 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2231 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2232 | named2!(expr_ret(allow_struct: AllowStruct) -> Expr, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2233 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2234 | return_: keyword!(return) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 2235 | // NOTE: return is greedy and eats blocks after it even when in a |
| 2236 | // position where structs are not allowed, such as in if statement |
| 2237 | // conditions. For example: |
| 2238 | // |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 2239 | // if return { println!("A") } {} // Prints "A" |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 2240 | ret_value: option!(ambiguous_expr!(allow_struct)) >> |
David Tolnay | c246cd3 | 2017-12-28 23:14:32 -0500 | [diff] [blame] | 2241 | (ExprReturn { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2242 | attrs: attrs, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2243 | expr: ret_value.map(Box::new), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2244 | return_token: return_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2245 | }.into()) |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 2246 | )); |
| 2247 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2248 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2249 | impl Synom for ExprStruct { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2250 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2251 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2252 | path: syn!(Path) >> |
| 2253 | data: braces!(do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2254 | inner_attrs: many0!(Attribute::old_parse_inner) >> |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2255 | fields: call!(Punctuated::parse_terminated) >> |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2256 | base: option!(cond!(fields.empty_or_trailing(), do_parse!( |
| 2257 | dots: punct!(..) >> |
| 2258 | base: syn!(Expr) >> |
| 2259 | (dots, base) |
| 2260 | ))) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2261 | (inner_attrs, fields, base) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2262 | )) >> |
| 2263 | ({ |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2264 | let (brace, (inner_attrs, fields, base)) = data; |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2265 | let (dots, rest) = match base.and_then(|b| b) { |
| 2266 | Some((dots, base)) => (Some(dots), Some(base)), |
| 2267 | None => (None, None), |
| 2268 | }; |
| 2269 | ExprStruct { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2270 | attrs: { |
| 2271 | let mut attrs = outer_attrs; |
| 2272 | attrs.extend(inner_attrs); |
| 2273 | attrs |
| 2274 | }, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2275 | brace_token: brace, |
| 2276 | path: path, |
| 2277 | fields: fields, |
| 2278 | dot2_token: dots, |
| 2279 | rest: rest.map(Box::new), |
| 2280 | } |
| 2281 | }) |
| 2282 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2285 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2286 | impl Synom for FieldValue { |
David Tolnay | c42b90a | 2018-01-18 23:11:37 -0800 | [diff] [blame] | 2287 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2288 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | c42b90a | 2018-01-18 23:11:37 -0800 | [diff] [blame] | 2289 | field_value: alt!( |
| 2290 | tuple!(syn!(Member), map!(punct!(:), Some), syn!(Expr)) |
| 2291 | | |
| 2292 | map!(syn!(Ident), |name| ( |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 2293 | Member::Named(name.clone()), |
David Tolnay | c42b90a | 2018-01-18 23:11:37 -0800 | [diff] [blame] | 2294 | None, |
| 2295 | Expr::Path(ExprPath { |
| 2296 | attrs: Vec::new(), |
| 2297 | qself: None, |
| 2298 | path: name.into(), |
| 2299 | }), |
| 2300 | )) |
| 2301 | ) >> |
| 2302 | (FieldValue { |
| 2303 | attrs: attrs, |
| 2304 | member: field_value.0, |
| 2305 | colon_token: field_value.1, |
| 2306 | expr: field_value.2, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2307 | }) |
| 2308 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2309 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 2310 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2311 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2312 | impl Synom for ExprRepeat { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2313 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2314 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2315 | data: brackets!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2316 | many0!(Attribute::old_parse_inner), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2317 | syn!(Expr), |
| 2318 | punct!(;), |
David Tolnay | 0235ba6 | 2018-07-21 19:20:50 -0700 | [diff] [blame] | 2319 | syn!(Expr), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2320 | )) >> |
| 2321 | (ExprRepeat { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2322 | attrs: { |
| 2323 | let mut attrs = outer_attrs; |
| 2324 | attrs.extend((data.1).0); |
| 2325 | attrs |
| 2326 | }, |
| 2327 | expr: Box::new((data.1).1), |
| 2328 | len: Box::new((data.1).3), |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 2329 | bracket_token: data.0, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2330 | semi_token: (data.1).2, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2331 | }) |
| 2332 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2333 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 2334 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2335 | #[cfg(feature = "full")] |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 2336 | impl Synom for ExprUnsafe { |
| 2337 | named!(parse -> Self, do_parse!( |
David Tolnay | 8b49377 | 2018-08-27 06:30:18 -0700 | [diff] [blame] | 2338 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 2339 | unsafe_: keyword!(unsafe) >> |
David Tolnay | c4be351 | 2018-08-27 06:25:44 -0700 | [diff] [blame] | 2340 | block: braces!(tuple!( |
David Tolnay | 8b49377 | 2018-08-27 06:30:18 -0700 | [diff] [blame] | 2341 | many0!(Attribute::old_parse_inner), |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2342 | shim!(Block::parse_within), |
David Tolnay | c4be351 | 2018-08-27 06:25:44 -0700 | [diff] [blame] | 2343 | )) >> |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 2344 | (ExprUnsafe { |
David Tolnay | c4be351 | 2018-08-27 06:25:44 -0700 | [diff] [blame] | 2345 | attrs: { |
| 2346 | let mut attrs = outer_attrs; |
| 2347 | attrs.extend((block.1).0); |
| 2348 | attrs |
| 2349 | }, |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 2350 | unsafe_token: unsafe_, |
David Tolnay | c4be351 | 2018-08-27 06:25:44 -0700 | [diff] [blame] | 2351 | block: Block { |
| 2352 | brace_token: block.0, |
| 2353 | stmts: (block.1).1, |
| 2354 | }, |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 2355 | }) |
| 2356 | )); |
| 2357 | } |
| 2358 | |
| 2359 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2360 | impl Synom for ExprBlock { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2361 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2362 | outer_attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 1d8e996 | 2018-08-24 19:04:20 -0400 | [diff] [blame] | 2363 | label: option!(syn!(Label)) >> |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2364 | block: braces!(tuple!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2365 | many0!(Attribute::old_parse_inner), |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2366 | shim!(Block::parse_within), |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2367 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2368 | (ExprBlock { |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2369 | attrs: { |
| 2370 | let mut attrs = outer_attrs; |
| 2371 | attrs.extend((block.1).0); |
| 2372 | attrs |
| 2373 | }, |
David Tolnay | 1d8e996 | 2018-08-24 19:04:20 -0400 | [diff] [blame] | 2374 | label: label, |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2375 | block: Block { |
| 2376 | brace_token: block.0, |
| 2377 | stmts: (block.1).1, |
| 2378 | }, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2379 | }) |
| 2380 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2381 | } |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 2382 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2383 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2384 | named2!(expr_range(allow_struct: AllowStruct) -> Expr, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2385 | limits: syn!(RangeLimits) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 2386 | hi: opt_ambiguous_expr!(allow_struct) >> |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2387 | (ExprRange { |
| 2388 | attrs: Vec::new(), |
| 2389 | from: None, |
| 2390 | to: hi.map(Box::new), |
| 2391 | limits: limits, |
| 2392 | }.into()) |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 2393 | )); |
| 2394 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2395 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2396 | impl Synom for RangeLimits { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2397 | named!(parse -> Self, alt!( |
| 2398 | // Must come before Dot2 |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 2399 | punct!(..=) => { RangeLimits::Closed } |
| 2400 | | |
| 2401 | // Must come before Dot2 |
David Tolnay | 7ac699c | 2018-08-24 14:00:58 -0400 | [diff] [blame] | 2402 | punct!(...) => { |dot3| RangeLimits::Closed(Token) } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2403 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2404 | punct!(..) => { RangeLimits::HalfOpen } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2405 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2406 | } |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 2407 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2408 | impl Synom for ExprPath { |
David Tolnay | eb981bb | 2018-07-21 19:31:38 -0700 | [diff] [blame] | 2409 | #[cfg(not(feature = "full"))] |
| 2410 | named!(parse -> Self, do_parse!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2411 | pair: shim!(qpath) >> |
David Tolnay | eb981bb | 2018-07-21 19:31:38 -0700 | [diff] [blame] | 2412 | (ExprPath { |
| 2413 | attrs: Vec::new(), |
| 2414 | qself: pair.0, |
| 2415 | path: pair.1, |
| 2416 | }) |
| 2417 | )); |
| 2418 | |
| 2419 | #[cfg(feature = "full")] |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2420 | named!(parse -> Self, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2421 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2422 | pair: shim!(qpath) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2423 | (ExprPath { |
David Tolnay | 73c9b52 | 2018-07-21 15:58:40 -0700 | [diff] [blame] | 2424 | attrs: attrs, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2425 | qself: pair.0, |
| 2426 | path: pair.1, |
| 2427 | }) |
| 2428 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2429 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2430 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2431 | named2!(path -> Path, do_parse!( |
David Tolnay | 9cc2f09 | 2018-08-24 15:51:37 -0400 | [diff] [blame] | 2432 | colon: option!(punct!(::)) >> |
| 2433 | segments: call!(Punctuated::<_, Token![::]>::parse_separated_nonempty_with, path_segment) >> |
| 2434 | cond_reduce!(segments.first().map_or(true, |seg| seg.value().ident != "dyn")) >> |
| 2435 | (Path { |
| 2436 | leading_colon: colon, |
| 2437 | segments: segments, |
| 2438 | }) |
| 2439 | )); |
| 2440 | |
| 2441 | named!(path_segment -> PathSegment, alt!( |
| 2442 | do_parse!( |
| 2443 | ident: syn!(Ident) >> |
| 2444 | colon2: punct!(::) >> |
| 2445 | lt: punct!(<) >> |
| 2446 | args: call!(Punctuated::parse_terminated) >> |
| 2447 | gt: punct!(>) >> |
| 2448 | (PathSegment { |
| 2449 | ident: ident, |
| 2450 | arguments: PathArguments::AngleBracketed(AngleBracketedGenericArguments { |
| 2451 | colon2_token: Some(colon2), |
| 2452 | lt_token: lt, |
| 2453 | args: args, |
| 2454 | gt_token: gt, |
| 2455 | }), |
| 2456 | }) |
| 2457 | ) |
| 2458 | | |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 2459 | old_mod_style_path_segment |
David Tolnay | 9cc2f09 | 2018-08-24 15:51:37 -0400 | [diff] [blame] | 2460 | )); |
| 2461 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2462 | named2!(qpath -> (Option<QSelf>, Path), alt!( |
| 2463 | map!(shim!(path), |p| (None, p)) |
David Tolnay | 9cc2f09 | 2018-08-24 15:51:37 -0400 | [diff] [blame] | 2464 | | |
| 2465 | do_parse!( |
| 2466 | lt: punct!(<) >> |
| 2467 | this: syn!(Type) >> |
| 2468 | path: option!(tuple!(keyword!(as), syn!(Path))) >> |
| 2469 | gt: punct!(>) >> |
| 2470 | colon2: punct!(::) >> |
| 2471 | rest: call!(Punctuated::parse_separated_nonempty_with, path_segment) >> |
| 2472 | ({ |
| 2473 | let (pos, as_, path) = match path { |
| 2474 | Some((as_, mut path)) => { |
| 2475 | let pos = path.segments.len(); |
| 2476 | path.segments.push_punct(colon2); |
| 2477 | path.segments.extend(rest.into_pairs()); |
| 2478 | (pos, Some(as_), path) |
| 2479 | } |
| 2480 | None => { |
| 2481 | (0, None, Path { |
| 2482 | leading_colon: Some(colon2), |
| 2483 | segments: rest, |
| 2484 | }) |
| 2485 | } |
| 2486 | }; |
| 2487 | (Some(QSelf { |
| 2488 | lt_token: lt, |
| 2489 | ty: Box::new(this), |
| 2490 | position: pos, |
| 2491 | as_token: as_, |
| 2492 | gt_token: gt, |
| 2493 | }), path) |
| 2494 | }) |
| 2495 | ) |
| 2496 | | |
| 2497 | map!(keyword!(self), |s| (None, s.into())) |
| 2498 | )); |
| 2499 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2500 | named2!(and_field -> (Token![.], Member), tuple!(punct!(.), syn!(Member))); |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 2501 | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2502 | named2!(and_index -> (token::Bracket, Expr), brackets!(syn!(Expr))); |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 2503 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2504 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2505 | impl Synom for Block { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2506 | named!(parse -> Self, do_parse!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2507 | stmts: braces!(Block::old_parse_within) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2508 | (Block { |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 2509 | brace_token: stmts.0, |
| 2510 | stmts: stmts.1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2511 | }) |
| 2512 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2513 | } |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 2514 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2515 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2516 | impl Block { |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2517 | pub fn parse_within(input: ParseStream) -> Result<Vec<Stmt>> { |
| 2518 | input.step_cursor(|cursor| Self::old_parse_within(*cursor)) |
| 2519 | } |
| 2520 | |
| 2521 | named!(old_parse_within -> Vec<Stmt>, do_parse!( |
David Tolnay | 4699a31 | 2017-12-27 14:39:22 -0500 | [diff] [blame] | 2522 | many0!(punct!(;)) >> |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2523 | mut standalone: many0!(do_parse!( |
| 2524 | stmt: syn!(Stmt) >> |
| 2525 | many0!(punct!(;)) >> |
| 2526 | (stmt) |
| 2527 | )) >> |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 2528 | last: option!(do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2529 | attrs: many0!(Attribute::old_parse_outer) >> |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 2530 | mut e: syn!(Expr) >> |
| 2531 | ({ |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 2532 | e.replace_attrs(attrs); |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2533 | Stmt::Expr(e) |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 2534 | }) |
| 2535 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2536 | (match last { |
| 2537 | None => standalone, |
| 2538 | Some(last) => { |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 2539 | standalone.push(last); |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2540 | standalone |
| 2541 | } |
| 2542 | }) |
| 2543 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2546 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2547 | impl Synom for Stmt { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2548 | named!(parse -> Self, alt!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2549 | shim!(stmt_mac) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2550 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2551 | shim!(stmt_local) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2552 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2553 | shim!(stmt_item) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2554 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2555 | shim!(stmt_blockexpr) |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 2556 | | |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2557 | shim!(stmt_expr) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2558 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2559 | } |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 2560 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2561 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2562 | named2!(stmt_mac -> Stmt, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2563 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | a7d69fc | 2018-08-26 13:30:24 -0400 | [diff] [blame] | 2564 | what: call!(Path::old_parse_mod_style) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2565 | bang: punct!(!) >> |
David Tolnay | eea28d6 | 2016-10-25 20:44:08 -0700 | [diff] [blame] | 2566 | // Only parse braces here; paren and bracket will get parsed as |
| 2567 | // expression statements |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2568 | data: braces!(syn!(TokenStream)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2569 | semi: option!(punct!(;)) >> |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2570 | (Stmt::Item(Item::Macro(ItemMacro { |
David Tolnay | 57b52bc | 2017-12-28 18:06:38 -0500 | [diff] [blame] | 2571 | attrs: attrs, |
| 2572 | ident: None, |
| 2573 | mac: Macro { |
David Tolnay | 5d55ef7 | 2016-12-21 20:20:04 -0500 | [diff] [blame] | 2574 | path: what, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2575 | bang_token: bang, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 2576 | delimiter: MacroDelimiter::Brace(data.0), |
| 2577 | tts: data.1, |
David Tolnay | eea28d6 | 2016-10-25 20:44:08 -0700 | [diff] [blame] | 2578 | }, |
David Tolnay | 57b52bc | 2017-12-28 18:06:38 -0500 | [diff] [blame] | 2579 | semi_token: semi, |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2580 | }))) |
David Tolnay | 13b3d35 | 2016-10-03 00:31:15 -0700 | [diff] [blame] | 2581 | )); |
| 2582 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2583 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2584 | named2!(stmt_local -> Stmt, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2585 | attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2586 | let_: keyword!(let) >> |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 2587 | pats: call!(Punctuated::parse_separated_nonempty) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 2588 | ty: option!(tuple!(punct!(:), syn!(Type))) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2589 | init: option!(tuple!(punct!(=), syn!(Expr))) >> |
| 2590 | semi: punct!(;) >> |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2591 | (Stmt::Local(Local { |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2592 | attrs: attrs, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 2593 | let_token: let_, |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 2594 | pats: pats, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 2595 | ty: ty.map(|(colon, ty)| (colon, Box::new(ty))), |
| 2596 | init: init.map(|(eq, expr)| (eq, Box::new(expr))), |
| 2597 | semi_token: semi, |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2598 | })) |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2599 | )); |
| 2600 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2601 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2602 | named2!(stmt_item -> Stmt, map!(syn!(Item), |i| Stmt::Item(i))); |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2603 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2604 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2605 | named2!(stmt_blockexpr -> Stmt, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2606 | mut attrs: many0!(Attribute::old_parse_outer) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2607 | mut e: shim!(expr_nosemi) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2608 | semi: option!(punct!(;)) >> |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 2609 | ({ |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2610 | attrs.extend(e.replace_attrs(Vec::new())); |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 2611 | e.replace_attrs(attrs); |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 2612 | if let Some(semi) = semi { |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2613 | Stmt::Semi(e, semi) |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 2614 | } else { |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2615 | Stmt::Expr(e) |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 2616 | } |
| 2617 | }) |
| 2618 | )); |
David Tolnay | cfe5502 | 2016-10-02 22:02:27 -0700 | [diff] [blame] | 2619 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2620 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2621 | named2!(stmt_expr -> Stmt, do_parse!( |
David Tolnay | f8106f8 | 2018-08-25 21:17:45 -0400 | [diff] [blame] | 2622 | mut attrs: many0!(Attribute::old_parse_outer) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2623 | mut e: syn!(Expr) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2624 | semi: punct!(;) >> |
David Tolnay | 7184b13 | 2016-10-30 10:06:37 -0700 | [diff] [blame] | 2625 | ({ |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 2626 | attrs.extend(e.replace_attrs(Vec::new())); |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 2627 | e.replace_attrs(attrs); |
David Tolnay | 1f0b7b8 | 2018-01-06 16:07:14 -0800 | [diff] [blame] | 2628 | Stmt::Semi(e, semi) |
David Tolnay | cfe5502 | 2016-10-02 22:02:27 -0700 | [diff] [blame] | 2629 | }) |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 2630 | )); |
David Tolnay | 8b07f37 | 2016-09-30 10:28:40 -0700 | [diff] [blame] | 2631 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2632 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2633 | impl Synom for Pat { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2634 | named!(parse -> Self, alt!( |
| 2635 | syn!(PatWild) => { Pat::Wild } // must be before pat_ident |
| 2636 | | |
| 2637 | syn!(PatBox) => { Pat::Box } // must be before pat_ident |
| 2638 | | |
| 2639 | syn!(PatRange) => { Pat::Range } // must be before pat_lit |
| 2640 | | |
| 2641 | syn!(PatTupleStruct) => { Pat::TupleStruct } // must be before pat_ident |
| 2642 | | |
| 2643 | syn!(PatStruct) => { Pat::Struct } // must be before pat_ident |
| 2644 | | |
David Tolnay | 323279a | 2017-12-29 11:26:32 -0500 | [diff] [blame] | 2645 | syn!(PatMacro) => { Pat::Macro } // must be before pat_ident |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2646 | | |
| 2647 | syn!(PatLit) => { Pat::Lit } // must be before pat_ident |
| 2648 | | |
| 2649 | syn!(PatIdent) => { Pat::Ident } // must be before pat_path |
| 2650 | | |
| 2651 | syn!(PatPath) => { Pat::Path } |
| 2652 | | |
| 2653 | syn!(PatTuple) => { Pat::Tuple } |
| 2654 | | |
| 2655 | syn!(PatRef) => { Pat::Ref } |
| 2656 | | |
| 2657 | syn!(PatSlice) => { Pat::Slice } |
| 2658 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2659 | } |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2660 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2661 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2662 | impl Synom for PatWild { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2663 | named!(parse -> Self, map!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2664 | punct!(_), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2665 | |u| PatWild { underscore_token: u } |
| 2666 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2667 | } |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 2668 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2669 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2670 | impl Synom for PatBox { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2671 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2672 | boxed: keyword!(box) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2673 | pat: syn!(Pat) >> |
| 2674 | (PatBox { |
| 2675 | pat: Box::new(pat), |
| 2676 | box_token: boxed, |
| 2677 | }) |
| 2678 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2679 | } |
| 2680 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2681 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2682 | impl Synom for PatIdent { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2683 | named!(parse -> Self, do_parse!( |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 2684 | by_ref: option!(keyword!(ref)) >> |
| 2685 | mutability: option!(keyword!(mut)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2686 | name: alt!( |
| 2687 | syn!(Ident) |
| 2688 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2689 | keyword!(self) => { Into::into } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2690 | ) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2691 | not!(punct!(<)) >> |
| 2692 | not!(punct!(::)) >> |
| 2693 | subpat: option!(tuple!(punct!(@), syn!(Pat))) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2694 | (PatIdent { |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 2695 | by_ref: by_ref, |
David Tolnay | efc96fb | 2017-12-29 02:03:15 -0500 | [diff] [blame] | 2696 | mutability: mutability, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2697 | ident: name, |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 2698 | subpat: subpat.map(|(at, pat)| (at, Box::new(pat))), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2699 | }) |
| 2700 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2703 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2704 | impl Synom for PatTupleStruct { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2705 | named!(parse -> Self, do_parse!( |
| 2706 | path: syn!(Path) >> |
| 2707 | tuple: syn!(PatTuple) >> |
| 2708 | (PatTupleStruct { |
| 2709 | path: path, |
| 2710 | pat: tuple, |
| 2711 | }) |
| 2712 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2715 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2716 | impl Synom for PatStruct { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2717 | named!(parse -> Self, do_parse!( |
| 2718 | path: syn!(Path) >> |
| 2719 | data: braces!(do_parse!( |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2720 | fields: call!(Punctuated::parse_terminated) >> |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2721 | base: option!(cond!(fields.empty_or_trailing(), punct!(..))) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2722 | (fields, base) |
| 2723 | )) >> |
| 2724 | (PatStruct { |
| 2725 | path: path, |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 2726 | fields: (data.1).0, |
| 2727 | brace_token: data.0, |
| 2728 | dot2_token: (data.1).1.and_then(|m| m), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2729 | }) |
| 2730 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2733 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2734 | impl Synom for FieldPat { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2735 | named!(parse -> Self, alt!( |
| 2736 | do_parse!( |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2737 | member: syn!(Member) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2738 | colon: punct!(:) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2739 | pat: syn!(Pat) >> |
| 2740 | (FieldPat { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2741 | member: member, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2742 | pat: Box::new(pat), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2743 | attrs: Vec::new(), |
| 2744 | colon_token: Some(colon), |
| 2745 | }) |
| 2746 | ) |
| 2747 | | |
| 2748 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2749 | boxed: option!(keyword!(box)) >> |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 2750 | by_ref: option!(keyword!(ref)) >> |
| 2751 | mutability: option!(keyword!(mut)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2752 | ident: syn!(Ident) >> |
| 2753 | ({ |
| 2754 | let mut pat: Pat = PatIdent { |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 2755 | by_ref: by_ref, |
David Tolnay | efc96fb | 2017-12-29 02:03:15 -0500 | [diff] [blame] | 2756 | mutability: mutability, |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 2757 | ident: ident.clone(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2758 | subpat: None, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2759 | }.into(); |
| 2760 | if let Some(boxed) = boxed { |
| 2761 | pat = PatBox { |
| 2762 | pat: Box::new(pat), |
| 2763 | box_token: boxed, |
| 2764 | }.into(); |
| 2765 | } |
| 2766 | FieldPat { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2767 | member: Member::Named(ident), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2768 | pat: Box::new(pat), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2769 | attrs: Vec::new(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2770 | colon_token: None, |
| 2771 | } |
| 2772 | }) |
| 2773 | ) |
| 2774 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2777 | impl Synom for Member { |
| 2778 | named!(parse -> Self, alt!( |
| 2779 | syn!(Ident) => { Member::Named } |
| 2780 | | |
| 2781 | syn!(Index) => { Member::Unnamed } |
| 2782 | )); |
| 2783 | } |
| 2784 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2785 | impl Synom for Index { |
| 2786 | named!(parse -> Self, do_parse!( |
David Tolnay | 360efd2 | 2018-01-04 23:35:26 -0800 | [diff] [blame] | 2787 | lit: syn!(LitInt) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2788 | ({ |
David Tolnay | 360efd2 | 2018-01-04 23:35:26 -0800 | [diff] [blame] | 2789 | if let IntSuffix::None = lit.suffix() { |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 2790 | Index { index: lit.value() as u32, span: lit.span() } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2791 | } else { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2792 | return parse_error(); |
David Tolnay | da16738 | 2016-10-30 13:34:09 -0700 | [diff] [blame] | 2793 | } |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2794 | }) |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2795 | )); |
| 2796 | } |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2797 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2798 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2799 | impl Synom for PatPath { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2800 | named!(parse -> Self, map!( |
| 2801 | syn!(ExprPath), |
David Tolnay | bc7d7d9 | 2017-06-03 20:54:05 -0700 | [diff] [blame] | 2802 | |p| PatPath { qself: p.qself, path: p.path } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2803 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2804 | } |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 2805 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2806 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2807 | impl Synom for PatTuple { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2808 | named!(parse -> Self, do_parse!( |
| 2809 | data: parens!(do_parse!( |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2810 | front: call!(Punctuated::parse_terminated) >> |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2811 | dotdot: option!(cond_reduce!(front.empty_or_trailing(), |
| 2812 | tuple!(punct!(..), option!(punct!(,))) |
| 2813 | )) >> |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 2814 | back: cond!(match dotdot { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2815 | Some((_, Some(_))) => true, |
| 2816 | _ => false, |
| 2817 | }, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2818 | Punctuated::parse_terminated) >> |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 2819 | (front, dotdot, back) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2820 | )) >> |
| 2821 | ({ |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 2822 | let (parens, (front, dotdot, back)) = data; |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2823 | let (dotdot, trailing) = match dotdot { |
| 2824 | Some((a, b)) => (Some(a), Some(b)), |
| 2825 | None => (None, None), |
| 2826 | }; |
| 2827 | PatTuple { |
| 2828 | paren_token: parens, |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 2829 | front: front, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2830 | dot2_token: dotdot, |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 2831 | comma_token: trailing.unwrap_or_default(), |
| 2832 | back: back.unwrap_or_default(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2833 | } |
| 2834 | }) |
| 2835 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2836 | } |
David Tolnay | fbb7323 | 2016-10-03 01:00:06 -0700 | [diff] [blame] | 2837 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2838 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2839 | impl Synom for PatRef { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2840 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2841 | and: punct!(&) >> |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 2842 | mutability: option!(keyword!(mut)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2843 | pat: syn!(Pat) >> |
| 2844 | (PatRef { |
| 2845 | pat: Box::new(pat), |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 2846 | mutability: mutability, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2847 | and_token: and, |
| 2848 | }) |
| 2849 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2850 | } |
David Tolnay | ffdb97f | 2016-10-03 01:28:33 -0700 | [diff] [blame] | 2851 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2852 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2853 | impl Synom for PatLit { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2854 | named!(parse -> Self, do_parse!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2855 | lit: shim!(pat_lit_expr) >> |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2856 | (if let Expr::Path(_) = lit { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2857 | return parse_error(); // these need to be parsed by pat_path |
| 2858 | } else { |
| 2859 | PatLit { |
| 2860 | expr: Box::new(lit), |
| 2861 | } |
| 2862 | }) |
| 2863 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2864 | } |
David Tolnay | e131090 | 2016-10-29 23:40:00 -0700 | [diff] [blame] | 2865 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2866 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2867 | impl Synom for PatRange { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2868 | named!(parse -> Self, do_parse!( |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2869 | lo: shim!(pat_lit_expr) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2870 | limits: syn!(RangeLimits) >> |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2871 | hi: shim!(pat_lit_expr) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2872 | (PatRange { |
| 2873 | lo: Box::new(lo), |
| 2874 | hi: Box::new(hi), |
| 2875 | limits: limits, |
| 2876 | }) |
| 2877 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2878 | } |
David Tolnay | e131090 | 2016-10-29 23:40:00 -0700 | [diff] [blame] | 2879 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2880 | #[cfg(feature = "full")] |
David Tolnay | 9389c38 | 2018-08-27 09:13:37 -0700 | [diff] [blame] | 2881 | named2!(pat_lit_expr -> Expr, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2882 | neg: option!(punct!(-)) >> |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2883 | v: alt!( |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2884 | syn!(ExprLit) => { Expr::Lit } |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2885 | | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2886 | syn!(ExprPath) => { Expr::Path } |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2887 | ) >> |
David Tolnay | c29b989 | 2017-12-27 22:58:14 -0500 | [diff] [blame] | 2888 | (if let Some(neg) = neg { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2889 | Expr::Unary(ExprUnary { |
| 2890 | attrs: Vec::new(), |
David Tolnay | c29b989 | 2017-12-27 22:58:14 -0500 | [diff] [blame] | 2891 | op: UnOp::Neg(neg), |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 2892 | expr: Box::new(v) |
| 2893 | }) |
David Tolnay | 0ad9e9f | 2016-10-29 22:20:02 -0700 | [diff] [blame] | 2894 | } else { |
David Tolnay | 3bc597f | 2017-12-31 02:31:11 -0500 | [diff] [blame] | 2895 | v |
David Tolnay | 0ad9e9f | 2016-10-29 22:20:02 -0700 | [diff] [blame] | 2896 | }) |
| 2897 | )); |
David Tolnay | 8b308c2 | 2016-10-03 01:24:10 -0700 | [diff] [blame] | 2898 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2899 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2900 | impl Synom for PatSlice { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2901 | named!(parse -> Self, map!( |
| 2902 | brackets!(do_parse!( |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2903 | before: call!(Punctuated::parse_terminated) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2904 | middle: option!(do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2905 | dots: punct!(..) >> |
| 2906 | trailing: option!(punct!(,)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2907 | (dots, trailing) |
| 2908 | )) >> |
| 2909 | after: cond!( |
| 2910 | match middle { |
| 2911 | Some((_, ref trailing)) => trailing.is_some(), |
| 2912 | _ => false, |
| 2913 | }, |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2914 | Punctuated::parse_terminated |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2915 | ) >> |
| 2916 | (before, middle, after) |
| 2917 | )), |
David Tolnay | 8875fca | 2017-12-31 13:52:37 -0500 | [diff] [blame] | 2918 | |(brackets, (before, middle, after))| { |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 2919 | let mut before: Punctuated<Pat, Token![,]> = before; |
| 2920 | let after: Option<Punctuated<Pat, Token![,]>> = after; |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2921 | let middle: Option<(Token![..], Option<Token![,]>)> = middle; |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2922 | PatSlice { |
David Tolnay | 7ac699c | 2018-08-24 14:00:58 -0400 | [diff] [blame] | 2923 | dot2_token: middle.as_ref().map(|m| Token), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2924 | comma_token: middle.as_ref().and_then(|m| { |
David Tolnay | 7ac699c | 2018-08-24 14:00:58 -0400 | [diff] [blame] | 2925 | m.1.as_ref().map(|m| Token) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2926 | }), |
| 2927 | bracket_token: brackets, |
| 2928 | middle: middle.and_then(|_| { |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2929 | if before.empty_or_trailing() { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2930 | None |
David Tolnay | dc03aec | 2017-12-30 01:54:18 -0500 | [diff] [blame] | 2931 | } else { |
David Tolnay | 5608068 | 2018-01-06 14:01:52 -0800 | [diff] [blame] | 2932 | Some(Box::new(before.pop().unwrap().into_value())) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2933 | } |
| 2934 | }), |
| 2935 | front: before, |
| 2936 | back: after.unwrap_or_default(), |
David Tolnay | e1f13c3 | 2016-10-29 23:34:40 -0700 | [diff] [blame] | 2937 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2938 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2939 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2940 | } |
David Tolnay | 323279a | 2017-12-29 11:26:32 -0500 | [diff] [blame] | 2941 | |
| 2942 | #[cfg(feature = "full")] |
| 2943 | impl Synom for PatMacro { |
| 2944 | named!(parse -> Self, map!(syn!(Macro), |mac| PatMacro { mac: mac })); |
| 2945 | } |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2948 | #[cfg(feature = "printing")] |
| 2949 | mod printing { |
| 2950 | use super::*; |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2951 | #[cfg(feature = "full")] |
David Tolnay | 13b3d35 | 2016-10-03 00:31:15 -0700 | [diff] [blame] | 2952 | use attr::FilterAttrs; |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 2953 | use proc_macro2::{Literal, TokenStream}; |
| 2954 | use quote::{ToTokens, TokenStreamExt}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2955 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 2956 | // If the given expression is a bare `ExprStruct`, wraps it in parenthesis |
David Tolnay | b6a0e7d | 2018-05-20 22:06:47 -0700 | [diff] [blame] | 2957 | // before appending it to `TokenStream`. |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2958 | #[cfg(feature = "full")] |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 2959 | fn wrap_bare_struct(tokens: &mut TokenStream, e: &Expr) { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2960 | if let Expr::Struct(_) = *e { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 2961 | token::Paren::default().surround(tokens, |tokens| { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2962 | e.to_tokens(tokens); |
| 2963 | }); |
| 2964 | } else { |
| 2965 | e.to_tokens(tokens); |
| 2966 | } |
| 2967 | } |
| 2968 | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2969 | #[cfg(feature = "full")] |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 2970 | fn outer_attrs_to_tokens(attrs: &[Attribute], tokens: &mut TokenStream) { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2971 | tokens.append_all(attrs.outer()); |
| 2972 | } |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2973 | |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 2974 | #[cfg(feature = "full")] |
| 2975 | fn inner_attrs_to_tokens(attrs: &[Attribute], tokens: &mut TokenStream) { |
| 2976 | tokens.append_all(attrs.inner()); |
| 2977 | } |
| 2978 | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 2979 | #[cfg(not(feature = "full"))] |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 2980 | fn outer_attrs_to_tokens(_attrs: &[Attribute], _tokens: &mut TokenStream) {} |
| 2981 | |
| 2982 | #[cfg(not(feature = "full"))] |
| 2983 | fn inner_attrs_to_tokens(_attrs: &[Attribute], _tokens: &mut TokenStream) {} |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2984 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2985 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2986 | impl ToTokens for ExprBox { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 2987 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 2988 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2989 | self.box_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2990 | self.expr.to_tokens(tokens); |
| 2991 | } |
| 2992 | } |
| 2993 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2994 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2995 | impl ToTokens for ExprInPlace { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 2996 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 2997 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 8701a5c | 2017-12-28 23:31:10 -0500 | [diff] [blame] | 2998 | self.place.to_tokens(tokens); |
| 2999 | self.arrow_token.to_tokens(tokens); |
| 3000 | self.value.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3004 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3005 | impl ToTokens for ExprArray { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3006 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3007 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3008 | self.bracket_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3009 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 2a86fdd | 2017-12-28 23:34:28 -0500 | [diff] [blame] | 3010 | self.elems.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3011 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3012 | } |
| 3013 | } |
| 3014 | |
| 3015 | impl ToTokens for ExprCall { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3016 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3017 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3018 | self.func.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3019 | self.paren_token.surround(tokens, |tokens| { |
| 3020 | self.args.to_tokens(tokens); |
| 3021 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3025 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3026 | impl ToTokens for ExprMethodCall { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3027 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3028 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 7641851 | 2017-12-28 23:47:47 -0500 | [diff] [blame] | 3029 | self.receiver.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3030 | self.dot_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3031 | self.method.to_tokens(tokens); |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 3032 | self.turbofish.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3033 | self.paren_token.surround(tokens, |tokens| { |
| 3034 | self.args.to_tokens(tokens); |
| 3035 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3036 | } |
| 3037 | } |
| 3038 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3039 | #[cfg(feature = "full")] |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 3040 | impl ToTokens for MethodTurbofish { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3041 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 3042 | self.colon2_token.to_tokens(tokens); |
| 3043 | self.lt_token.to_tokens(tokens); |
| 3044 | self.args.to_tokens(tokens); |
| 3045 | self.gt_token.to_tokens(tokens); |
| 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | #[cfg(feature = "full")] |
| 3050 | impl ToTokens for GenericMethodArgument { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3051 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d60cfec | 2017-12-29 00:21:38 -0500 | [diff] [blame] | 3052 | match *self { |
| 3053 | GenericMethodArgument::Type(ref t) => t.to_tokens(tokens), |
| 3054 | GenericMethodArgument::Const(ref c) => c.to_tokens(tokens), |
| 3055 | } |
| 3056 | } |
| 3057 | } |
| 3058 | |
| 3059 | #[cfg(feature = "full")] |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 3060 | impl ToTokens for ExprTuple { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3061 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3062 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3063 | self.paren_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3064 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 2a86fdd | 2017-12-28 23:34:28 -0500 | [diff] [blame] | 3065 | self.elems.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3066 | // If we only have one argument, we need a trailing comma to |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 3067 | // distinguish ExprTuple from ExprParen. |
David Tolnay | a0834b4 | 2018-01-01 21:30:02 -0800 | [diff] [blame] | 3068 | if self.elems.len() == 1 && !self.elems.trailing_punct() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 3069 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3070 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3071 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | impl ToTokens for ExprBinary { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3076 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3077 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3078 | self.left.to_tokens(tokens); |
| 3079 | self.op.to_tokens(tokens); |
| 3080 | self.right.to_tokens(tokens); |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | impl ToTokens for ExprUnary { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3085 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3086 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3087 | self.op.to_tokens(tokens); |
| 3088 | self.expr.to_tokens(tokens); |
| 3089 | } |
| 3090 | } |
| 3091 | |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 3092 | impl ToTokens for ExprLit { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3093 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3094 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 3095 | self.lit.to_tokens(tokens); |
| 3096 | } |
| 3097 | } |
| 3098 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3099 | impl ToTokens for ExprCast { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3100 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3101 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3102 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3103 | self.as_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3104 | self.ty.to_tokens(tokens); |
| 3105 | } |
| 3106 | } |
| 3107 | |
David Tolnay | 0cf94f2 | 2017-12-28 23:46:26 -0500 | [diff] [blame] | 3108 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3109 | impl ToTokens for ExprType { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3110 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3111 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3112 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3113 | self.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3114 | self.ty.to_tokens(tokens); |
| 3115 | } |
| 3116 | } |
| 3117 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3118 | #[cfg(feature = "full")] |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3119 | fn maybe_wrap_else(tokens: &mut TokenStream, else_: &Option<(Token![else], Box<Expr>)>) { |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 3120 | if let Some((ref else_token, ref else_)) = *else_ { |
| 3121 | else_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3122 | |
| 3123 | // If we are not one of the valid expressions to exist in an else |
| 3124 | // clause, wrap ourselves in a block. |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 3125 | match **else_ { |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 3126 | Expr::If(_) | Expr::IfLet(_) | Expr::Block(_) => { |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 3127 | else_.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3128 | } |
| 3129 | _ => { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 3130 | token::Brace::default().surround(tokens, |tokens| { |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 3131 | else_.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3132 | }); |
| 3133 | } |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | |
| 3138 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3139 | impl ToTokens for ExprIf { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3140 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3141 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3142 | self.if_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3143 | wrap_bare_struct(tokens, &self.cond); |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 3144 | self.then_branch.to_tokens(tokens); |
| 3145 | maybe_wrap_else(tokens, &self.else_branch); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3146 | } |
| 3147 | } |
| 3148 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3149 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3150 | impl ToTokens for ExprIfLet { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3151 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3152 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3153 | self.if_token.to_tokens(tokens); |
| 3154 | self.let_token.to_tokens(tokens); |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 3155 | self.pats.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3156 | self.eq_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3157 | wrap_bare_struct(tokens, &self.expr); |
David Tolnay | 2ccf32a | 2017-12-29 00:34:26 -0500 | [diff] [blame] | 3158 | self.then_branch.to_tokens(tokens); |
| 3159 | maybe_wrap_else(tokens, &self.else_branch); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3160 | } |
| 3161 | } |
| 3162 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3163 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3164 | impl ToTokens for ExprWhile { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3165 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3166 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 3167 | self.label.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3168 | self.while_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3169 | wrap_bare_struct(tokens, &self.cond); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3170 | self.body.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3171 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3172 | tokens.append_all(&self.body.stmts); |
| 3173 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3174 | } |
| 3175 | } |
| 3176 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3177 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3178 | impl ToTokens for ExprWhileLet { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3179 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3180 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 3181 | self.label.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3182 | self.while_token.to_tokens(tokens); |
| 3183 | self.let_token.to_tokens(tokens); |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 3184 | self.pats.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3185 | self.eq_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3186 | wrap_bare_struct(tokens, &self.expr); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3187 | self.body.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3188 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3189 | tokens.append_all(&self.body.stmts); |
| 3190 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3191 | } |
| 3192 | } |
| 3193 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3194 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3195 | impl ToTokens for ExprForLoop { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3196 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3197 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 3198 | self.label.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3199 | self.for_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3200 | self.pat.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3201 | self.in_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3202 | wrap_bare_struct(tokens, &self.expr); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3203 | self.body.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3204 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3205 | tokens.append_all(&self.body.stmts); |
| 3206 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3207 | } |
| 3208 | } |
| 3209 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3210 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3211 | impl ToTokens for ExprLoop { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3212 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3213 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 3214 | self.label.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3215 | self.loop_token.to_tokens(tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3216 | self.body.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3217 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3218 | tokens.append_all(&self.body.stmts); |
| 3219 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3220 | } |
| 3221 | } |
| 3222 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3223 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3224 | impl ToTokens for ExprMatch { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3225 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3226 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3227 | self.match_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3228 | wrap_bare_struct(tokens, &self.expr); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3229 | self.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3230 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 3231 | for (i, arm) in self.arms.iter().enumerate() { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3232 | arm.to_tokens(tokens); |
| 3233 | // Ensure that we have a comma after a non-block arm, except |
| 3234 | // for the last one. |
| 3235 | let is_last = i == self.arms.len() - 1; |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 3236 | if !is_last && arm_expr_requires_comma(&arm.body) && arm.comma.is_none() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 3237 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3238 | } |
| 3239 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3240 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3244 | #[cfg(feature = "full")] |
David Tolnay | 02a9c6f | 2018-08-24 18:58:45 -0400 | [diff] [blame] | 3245 | impl ToTokens for ExprAsync { |
| 3246 | fn to_tokens(&self, tokens: &mut TokenStream) { |
| 3247 | outer_attrs_to_tokens(&self.attrs, tokens); |
| 3248 | self.async_token.to_tokens(tokens); |
| 3249 | self.capture.to_tokens(tokens); |
| 3250 | self.block.to_tokens(tokens); |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | #[cfg(feature = "full")] |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 3255 | impl ToTokens for ExprTryBlock { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3256 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3257 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | fb2dd4b | 2018-08-24 16:45:34 -0400 | [diff] [blame] | 3258 | self.try_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3259 | self.block.to_tokens(tokens); |
| 3260 | } |
| 3261 | } |
| 3262 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3263 | #[cfg(feature = "full")] |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 3264 | impl ToTokens for ExprYield { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3265 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3266 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 3267 | self.yield_token.to_tokens(tokens); |
| 3268 | self.expr.to_tokens(tokens); |
| 3269 | } |
| 3270 | } |
| 3271 | |
| 3272 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3273 | impl ToTokens for ExprClosure { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3274 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3275 | outer_attrs_to_tokens(&self.attrs, tokens); |
Yusuke Sasaki | 4e5d966 | 2018-07-21 02:49:47 +0900 | [diff] [blame] | 3276 | self.asyncness.to_tokens(tokens); |
David Tolnay | 13d4c0e | 2018-03-31 20:53:59 +0200 | [diff] [blame] | 3277 | self.movability.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3278 | self.capture.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3279 | self.or1_token.to_tokens(tokens); |
David Tolnay | 5608068 | 2018-01-06 14:01:52 -0800 | [diff] [blame] | 3280 | for input in self.inputs.pairs() { |
| 3281 | match **input.value() { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 3282 | FnArg::Captured(ArgCaptured { |
| 3283 | ref pat, |
| 3284 | ty: Type::Infer(_), |
| 3285 | .. |
| 3286 | }) => { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3287 | pat.to_tokens(tokens); |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 3288 | } |
David Tolnay | 5608068 | 2018-01-06 14:01:52 -0800 | [diff] [blame] | 3289 | _ => input.value().to_tokens(tokens), |
David Tolnay | 3c2467c | 2016-10-02 17:55:08 -0700 | [diff] [blame] | 3290 | } |
David Tolnay | f2cfd72 | 2017-12-31 18:02:51 -0500 | [diff] [blame] | 3291 | input.punct().to_tokens(tokens); |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 3292 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3293 | self.or2_token.to_tokens(tokens); |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 3294 | self.output.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3295 | self.body.to_tokens(tokens); |
| 3296 | } |
| 3297 | } |
| 3298 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3299 | #[cfg(feature = "full")] |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 3300 | impl ToTokens for ExprUnsafe { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3301 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3302 | outer_attrs_to_tokens(&self.attrs, tokens); |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 3303 | self.unsafe_token.to_tokens(tokens); |
David Tolnay | c4be351 | 2018-08-27 06:25:44 -0700 | [diff] [blame] | 3304 | self.block.brace_token.surround(tokens, |tokens| { |
| 3305 | inner_attrs_to_tokens(&self.attrs, tokens); |
| 3306 | tokens.append_all(&self.block.stmts); |
| 3307 | }); |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 3308 | } |
| 3309 | } |
| 3310 | |
| 3311 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3312 | impl ToTokens for ExprBlock { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3313 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3314 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 1d8e996 | 2018-08-24 19:04:20 -0400 | [diff] [blame] | 3315 | self.label.to_tokens(tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3316 | self.block.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3317 | inner_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 5d314dc | 2018-07-21 16:40:01 -0700 | [diff] [blame] | 3318 | tokens.append_all(&self.block.stmts); |
| 3319 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3320 | } |
| 3321 | } |
| 3322 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3323 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3324 | impl ToTokens for ExprAssign { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3325 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3326 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3327 | self.left.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3328 | self.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3329 | self.right.to_tokens(tokens); |
| 3330 | } |
| 3331 | } |
| 3332 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3333 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3334 | impl ToTokens for ExprAssignOp { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3335 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3336 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3337 | self.left.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3338 | self.op.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3339 | self.right.to_tokens(tokens); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | impl ToTokens for ExprField { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3344 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3345 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3346 | self.base.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3347 | self.dot_token.to_tokens(tokens); |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3348 | self.member.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3349 | } |
| 3350 | } |
| 3351 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3352 | impl ToTokens for Member { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3353 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3354 | match *self { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3355 | Member::Named(ref ident) => ident.to_tokens(tokens), |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3356 | Member::Unnamed(ref index) => index.to_tokens(tokens), |
| 3357 | } |
| 3358 | } |
| 3359 | } |
| 3360 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3361 | impl ToTokens for Index { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3362 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | 9a4dca2 | 2018-03-28 06:32:19 -0700 | [diff] [blame] | 3363 | let mut lit = Literal::i64_unsuffixed(i64::from(self.index)); |
| 3364 | lit.set_span(self.span); |
| 3365 | tokens.append(lit); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3366 | } |
| 3367 | } |
| 3368 | |
| 3369 | impl ToTokens for ExprIndex { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3370 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3371 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3372 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3373 | self.bracket_token.surround(tokens, |tokens| { |
| 3374 | self.index.to_tokens(tokens); |
| 3375 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3379 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3380 | impl ToTokens for ExprRange { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3381 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3382 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3383 | self.from.to_tokens(tokens); |
David Tolnay | 475288a | 2017-12-19 22:59:44 -0800 | [diff] [blame] | 3384 | match self.limits { |
| 3385 | RangeLimits::HalfOpen(ref t) => t.to_tokens(tokens), |
| 3386 | RangeLimits::Closed(ref t) => t.to_tokens(tokens), |
| 3387 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3388 | self.to.to_tokens(tokens); |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | impl ToTokens for ExprPath { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3393 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3394 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3395 | ::PathTokens(&self.qself, &self.path).to_tokens(tokens) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3396 | } |
| 3397 | } |
| 3398 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3399 | #[cfg(feature = "full")] |
David Tolnay | 00674ba | 2018-03-31 18:14:11 +0200 | [diff] [blame] | 3400 | impl ToTokens for ExprReference { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3401 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3402 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3403 | self.and_token.to_tokens(tokens); |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 3404 | self.mutability.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3405 | self.expr.to_tokens(tokens); |
| 3406 | } |
| 3407 | } |
| 3408 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3409 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3410 | impl ToTokens for ExprBreak { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3411 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3412 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3413 | self.break_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3414 | self.label.to_tokens(tokens); |
| 3415 | self.expr.to_tokens(tokens); |
| 3416 | } |
| 3417 | } |
| 3418 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3419 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3420 | impl ToTokens for ExprContinue { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3421 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3422 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3423 | self.continue_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3424 | self.label.to_tokens(tokens); |
| 3425 | } |
| 3426 | } |
| 3427 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3428 | #[cfg(feature = "full")] |
David Tolnay | c246cd3 | 2017-12-28 23:14:32 -0500 | [diff] [blame] | 3429 | impl ToTokens for ExprReturn { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3430 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3431 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3432 | self.return_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3433 | self.expr.to_tokens(tokens); |
| 3434 | } |
| 3435 | } |
| 3436 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3437 | #[cfg(feature = "full")] |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 3438 | impl ToTokens for ExprMacro { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3439 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3440 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 8c91b88 | 2017-12-28 23:04:32 -0500 | [diff] [blame] | 3441 | self.mac.to_tokens(tokens); |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3446 | impl ToTokens for ExprStruct { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3447 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3448 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3449 | self.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3450 | self.brace_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3451 | inner_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3452 | self.fields.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3453 | if self.rest.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 3454 | TokensOrDefault(&self.dot2_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3455 | self.rest.to_tokens(tokens); |
| 3456 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3457 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3461 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3462 | impl ToTokens for ExprRepeat { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3463 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3464 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3465 | self.bracket_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3466 | inner_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3467 | self.expr.to_tokens(tokens); |
| 3468 | self.semi_token.to_tokens(tokens); |
David Tolnay | 84d8044 | 2018-01-07 01:03:20 -0800 | [diff] [blame] | 3469 | self.len.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3470 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3471 | } |
| 3472 | } |
| 3473 | |
David Tolnay | e98775f | 2017-12-28 23:17:00 -0500 | [diff] [blame] | 3474 | #[cfg(feature = "full")] |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 3475 | impl ToTokens for ExprGroup { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3476 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3477 | outer_attrs_to_tokens(&self.attrs, tokens); |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 3478 | self.group_token.surround(tokens, |tokens| { |
| 3479 | self.expr.to_tokens(tokens); |
| 3480 | }); |
| 3481 | } |
| 3482 | } |
| 3483 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3484 | impl ToTokens for ExprParen { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3485 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3486 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3487 | self.paren_token.surround(tokens, |tokens| { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3488 | inner_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3489 | self.expr.to_tokens(tokens); |
| 3490 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3491 | } |
| 3492 | } |
| 3493 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3494 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3495 | impl ToTokens for ExprTry { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3496 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3497 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 3498 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3499 | self.question_token.to_tokens(tokens); |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 3500 | } |
| 3501 | } |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 3502 | |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 3503 | impl ToTokens for ExprVerbatim { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3504 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 3505 | self.tts.to_tokens(tokens); |
| 3506 | } |
| 3507 | } |
| 3508 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3509 | #[cfg(feature = "full")] |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 3510 | impl ToTokens for Label { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3511 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | bcd498f | 2017-12-29 12:02:33 -0500 | [diff] [blame] | 3512 | self.name.to_tokens(tokens); |
| 3513 | self.colon_token.to_tokens(tokens); |
| 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | #[cfg(feature = "full")] |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 3518 | impl ToTokens for FieldValue { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3519 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3520 | outer_attrs_to_tokens(&self.attrs, tokens); |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3521 | self.member.to_tokens(tokens); |
David Tolnay | 5d7098a | 2017-12-29 01:35:24 -0500 | [diff] [blame] | 3522 | if let Some(ref colon_token) = self.colon_token { |
| 3523 | colon_token.to_tokens(tokens); |
David Tolnay | 276690f | 2016-10-30 12:06:59 -0700 | [diff] [blame] | 3524 | self.expr.to_tokens(tokens); |
| 3525 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3529 | #[cfg(feature = "full")] |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 3530 | impl ToTokens for Arm { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3531 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3532 | tokens.append_all(&self.attrs); |
David Tolnay | 18cc4d4 | 2018-03-31 18:47:20 +0200 | [diff] [blame] | 3533 | self.leading_vert.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3534 | self.pats.to_tokens(tokens); |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 3535 | if let Some((ref if_token, ref guard)) = self.guard { |
| 3536 | if_token.to_tokens(tokens); |
| 3537 | guard.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3538 | } |
David Tolnay | dfb9143 | 2018-03-31 19:19:44 +0200 | [diff] [blame] | 3539 | self.fat_arrow_token.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 3540 | self.body.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3541 | self.comma.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3545 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3546 | impl ToTokens for PatWild { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3547 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3548 | self.underscore_token.to_tokens(tokens); |
| 3549 | } |
| 3550 | } |
| 3551 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3552 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3553 | impl ToTokens for PatIdent { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3554 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 3555 | self.by_ref.to_tokens(tokens); |
David Tolnay | efc96fb | 2017-12-29 02:03:15 -0500 | [diff] [blame] | 3556 | self.mutability.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3557 | self.ident.to_tokens(tokens); |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 3558 | if let Some((ref at_token, ref subpat)) = self.subpat { |
| 3559 | at_token.to_tokens(tokens); |
| 3560 | subpat.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3561 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3565 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3566 | impl ToTokens for PatStruct { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3567 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3568 | self.path.to_tokens(tokens); |
| 3569 | self.brace_token.surround(tokens, |tokens| { |
| 3570 | self.fields.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3571 | // NOTE: We need a comma before the dot2 token if it is present. |
| 3572 | if !self.fields.empty_or_trailing() && self.dot2_token.is_some() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 3573 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3574 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3575 | self.dot2_token.to_tokens(tokens); |
| 3576 | }); |
| 3577 | } |
| 3578 | } |
| 3579 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3580 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3581 | impl ToTokens for PatTupleStruct { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3582 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3583 | self.path.to_tokens(tokens); |
| 3584 | self.pat.to_tokens(tokens); |
| 3585 | } |
| 3586 | } |
| 3587 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3588 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3589 | impl ToTokens for PatPath { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3590 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3591 | ::PathTokens(&self.qself, &self.path).to_tokens(tokens); |
| 3592 | } |
| 3593 | } |
| 3594 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3595 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3596 | impl ToTokens for PatTuple { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3597 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3598 | self.paren_token.surround(tokens, |tokens| { |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 3599 | self.front.to_tokens(tokens); |
| 3600 | if let Some(ref dot2_token) = self.dot2_token { |
| 3601 | if !self.front.empty_or_trailing() { |
| 3602 | // Ensure there is a comma before the .. token. |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 3603 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3604 | } |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 3605 | dot2_token.to_tokens(tokens); |
| 3606 | self.comma_token.to_tokens(tokens); |
| 3607 | if self.comma_token.is_none() && !self.back.is_empty() { |
| 3608 | // Ensure there is a comma after the .. token. |
| 3609 | <Token![,]>::default().to_tokens(tokens); |
| 3610 | } |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 3611 | } |
David Tolnay | 4187192 | 2017-12-29 01:53:45 -0500 | [diff] [blame] | 3612 | self.back.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3613 | }); |
| 3614 | } |
| 3615 | } |
| 3616 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3617 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3618 | impl ToTokens for PatBox { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3619 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3620 | self.box_token.to_tokens(tokens); |
| 3621 | self.pat.to_tokens(tokens); |
| 3622 | } |
| 3623 | } |
| 3624 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3625 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3626 | impl ToTokens for PatRef { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3627 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3628 | self.and_token.to_tokens(tokens); |
David Tolnay | 24237fb | 2017-12-29 02:15:26 -0500 | [diff] [blame] | 3629 | self.mutability.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3630 | self.pat.to_tokens(tokens); |
| 3631 | } |
| 3632 | } |
| 3633 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3634 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3635 | impl ToTokens for PatLit { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3636 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3637 | self.expr.to_tokens(tokens); |
| 3638 | } |
| 3639 | } |
| 3640 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3641 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3642 | impl ToTokens for PatRange { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3643 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3644 | self.lo.to_tokens(tokens); |
David Tolnay | 475288a | 2017-12-19 22:59:44 -0800 | [diff] [blame] | 3645 | match self.limits { |
| 3646 | RangeLimits::HalfOpen(ref t) => t.to_tokens(tokens), |
David Tolnay | 7ac699c | 2018-08-24 14:00:58 -0400 | [diff] [blame] | 3647 | RangeLimits::Closed(ref t) => Token.to_tokens(tokens), |
David Tolnay | 475288a | 2017-12-19 22:59:44 -0800 | [diff] [blame] | 3648 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3649 | self.hi.to_tokens(tokens); |
| 3650 | } |
| 3651 | } |
| 3652 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3653 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3654 | impl ToTokens for PatSlice { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3655 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3656 | // XXX: This is a mess, and it will be so easy to screw it up. How |
| 3657 | // do we make this correct itself better? |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3658 | self.bracket_token.surround(tokens, |tokens| { |
| 3659 | self.front.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3660 | |
| 3661 | // If we need a comma before the middle or standalone .. token, |
| 3662 | // then make sure it's present. |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 3663 | if !self.front.empty_or_trailing() |
| 3664 | && (self.middle.is_some() || self.dot2_token.is_some()) |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3665 | { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 3666 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | // If we have an identifier, we always need a .. token. |
| 3670 | if self.middle.is_some() { |
| 3671 | self.middle.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 3672 | TokensOrDefault(&self.dot2_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3673 | } else if self.dot2_token.is_some() { |
| 3674 | self.dot2_token.to_tokens(tokens); |
| 3675 | } |
| 3676 | |
| 3677 | // Make sure we have a comma before the back half. |
| 3678 | if !self.back.is_empty() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 3679 | TokensOrDefault(&self.comma_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3680 | self.back.to_tokens(tokens); |
| 3681 | } else { |
| 3682 | self.comma_token.to_tokens(tokens); |
| 3683 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3684 | }) |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 3685 | } |
| 3686 | } |
| 3687 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3688 | #[cfg(feature = "full")] |
David Tolnay | 323279a | 2017-12-29 11:26:32 -0500 | [diff] [blame] | 3689 | impl ToTokens for PatMacro { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3690 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 323279a | 2017-12-29 11:26:32 -0500 | [diff] [blame] | 3691 | self.mac.to_tokens(tokens); |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | #[cfg(feature = "full")] |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 3696 | impl ToTokens for PatVerbatim { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3697 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 2ae520a | 2017-12-29 11:19:50 -0500 | [diff] [blame] | 3698 | self.tts.to_tokens(tokens); |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | #[cfg(feature = "full")] |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 3703 | impl ToTokens for FieldPat { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3704 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 5d7098a | 2017-12-29 01:35:24 -0500 | [diff] [blame] | 3705 | if let Some(ref colon_token) = self.colon_token { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3706 | self.member.to_tokens(tokens); |
David Tolnay | 5d7098a | 2017-12-29 01:35:24 -0500 | [diff] [blame] | 3707 | colon_token.to_tokens(tokens); |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 3708 | } |
| 3709 | self.pat.to_tokens(tokens); |
| 3710 | } |
| 3711 | } |
| 3712 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3713 | #[cfg(feature = "full")] |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3714 | impl ToTokens for Block { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3715 | fn to_tokens(&self, tokens: &mut TokenStream) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3716 | self.brace_token.surround(tokens, |tokens| { |
| 3717 | tokens.append_all(&self.stmts); |
| 3718 | }); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3719 | } |
| 3720 | } |
| 3721 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3722 | #[cfg(feature = "full")] |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3723 | impl ToTokens for Stmt { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3724 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3725 | match *self { |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 3726 | Stmt::Local(ref local) => local.to_tokens(tokens), |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3727 | Stmt::Item(ref item) => item.to_tokens(tokens), |
| 3728 | Stmt::Expr(ref expr) => expr.to_tokens(tokens), |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3729 | Stmt::Semi(ref expr, ref semi) => { |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3730 | expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3731 | semi.to_tokens(tokens); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3732 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | } |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 3736 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 3737 | #[cfg(feature = "full")] |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 3738 | impl ToTokens for Local { |
Alex Crichton | a74a1c8 | 2018-05-16 10:20:44 -0700 | [diff] [blame] | 3739 | fn to_tokens(&self, tokens: &mut TokenStream) { |
David Tolnay | d997aef | 2018-07-21 18:42:31 -0700 | [diff] [blame] | 3740 | outer_attrs_to_tokens(&self.attrs, tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3741 | self.let_token.to_tokens(tokens); |
David Tolnay | 5b5b7d2 | 2018-03-31 21:05:00 +0200 | [diff] [blame] | 3742 | self.pats.to_tokens(tokens); |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 3743 | if let Some((ref colon_token, ref ty)) = self.ty { |
| 3744 | colon_token.to_tokens(tokens); |
| 3745 | ty.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3746 | } |
David Tolnay | 8b4d302 | 2017-12-29 12:11:10 -0500 | [diff] [blame] | 3747 | if let Some((ref eq_token, ref init)) = self.init { |
| 3748 | eq_token.to_tokens(tokens); |
| 3749 | init.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 3750 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 3751 | self.semi_token.to_tokens(tokens); |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 3752 | } |
| 3753 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 3754 | } |