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