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