David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 1 | use super::*; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2 | use delimited::Delimited; |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 3 | #[cfg(feature = "full")] |
| 4 | use proc_macro2::Span; |
| 5 | #[cfg(feature = "full")] |
| 6 | use std::hash::{Hash, Hasher}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 7 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 8 | ast_struct! { |
| 9 | /// An expression. |
| 10 | pub struct Expr { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 11 | /// Attributes tagged on the expression. |
| 12 | pub attrs: Vec<Attribute>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 13 | |
| 14 | /// Type of the expression. |
| 15 | pub node: ExprKind, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 16 | } |
David Tolnay | 7184b13 | 2016-10-30 10:06:37 -0700 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | impl From<ExprKind> for Expr { |
| 20 | fn from(node: ExprKind) -> Expr { |
| 21 | Expr { |
| 22 | node: node, |
| 23 | attrs: Vec::new(), |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 28 | ast_enum_of_structs! { |
| 29 | pub enum ExprKind { |
| 30 | /// A `box x` expression. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 31 | pub Box(ExprBox #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 32 | pub box_token: Token![box], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 33 | pub expr: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 34 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 35 | |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 36 | /// E.g. 'place <- val' or `in place { val }`. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 37 | pub InPlace(ExprInPlace #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 38 | pub place: Box<Expr>, |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 39 | pub kind: InPlaceKind, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 40 | pub value: Box<Expr>, |
| 41 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 42 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 43 | /// An array, e.g. `[a, b, c, d]`. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 44 | pub Array(ExprArray #full { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 45 | pub bracket_token: token::Bracket, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 46 | pub exprs: Delimited<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 47 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 48 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 49 | /// A function call. |
| 50 | pub Call(ExprCall { |
| 51 | pub func: Box<Expr>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 52 | pub paren_token: token::Paren, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 53 | pub args: Delimited<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 54 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 55 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 56 | /// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`) |
| 57 | /// |
| 58 | /// The `Ident` is the identifier for the method name. |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 59 | /// The vector of `Type`s are the ascripted type parameters for the method |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 60 | /// (within the angle brackets). |
| 61 | /// |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 62 | /// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as |
| 63 | /// `ExprKind::MethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 64 | pub MethodCall(ExprMethodCall #full { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 65 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 66 | pub dot_token: Token![.], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 67 | pub method: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 68 | pub colon2_token: Option<Token![::]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 69 | pub lt_token: Option<Token![<]>, |
| 70 | pub typarams: Delimited<Type, Token![,]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 71 | pub gt_token: Option<Token![>]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 72 | pub paren_token: token::Paren, |
| 73 | pub args: Delimited<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 74 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 75 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 76 | /// A tuple, e.g. `(a, b, c, d)`. |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 77 | pub Tuple(ExprTuple #full { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 78 | pub paren_token: token::Paren, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 79 | pub args: Delimited<Expr, Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 80 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 81 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 82 | /// A binary operation, e.g. `a + b`, `a * b`. |
| 83 | pub Binary(ExprBinary { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 84 | pub left: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 85 | pub op: BinOp, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 86 | pub right: Box<Expr>, |
| 87 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 88 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 89 | /// A unary operation, e.g. `!x`, `*x`. |
| 90 | pub Unary(ExprUnary { |
| 91 | pub op: UnOp, |
| 92 | pub expr: Box<Expr>, |
| 93 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 94 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 95 | /// A literal, e.g. `1`, `"foo"`. |
| 96 | pub Lit(Lit), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 97 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 98 | /// A cast, e.g. `foo as f64`. |
| 99 | pub Cast(ExprCast { |
| 100 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 101 | pub as_token: Token![as], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 102 | pub ty: Box<Type>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 103 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 104 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 105 | /// A type ascription, e.g. `foo: f64`. |
| 106 | pub Type(ExprType { |
| 107 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 108 | pub colon_token: Token![:], |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 109 | pub ty: Box<Type>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 110 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 111 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 112 | /// An `if` block, with an optional else block |
| 113 | /// |
| 114 | /// E.g., `if expr { block } else { expr }` |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 115 | pub If(ExprIf #full { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 116 | pub if_token: Token![if], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 117 | pub cond: Box<Expr>, |
| 118 | pub if_true: Block, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 119 | pub else_token: Option<Token![else]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 120 | pub if_false: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 121 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 122 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 123 | /// An `if let` expression with an optional else block |
| 124 | /// |
| 125 | /// E.g., `if let pat = expr { block } else { expr }` |
| 126 | /// |
| 127 | /// This is desugared to a `match` expression. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 128 | pub IfLet(ExprIfLet #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 129 | pub if_token: Token![if], |
| 130 | pub let_token: Token![let], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 131 | pub pat: Box<Pat>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 132 | pub eq_token: Token![=], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 133 | pub expr: Box<Expr>, |
| 134 | pub if_true: Block, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 135 | pub else_token: Option<Token![else]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 136 | pub if_false: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 137 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 138 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 139 | /// A while loop, with an optional label |
| 140 | /// |
| 141 | /// E.g., `'label: while expr { block }` |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 142 | pub While(ExprWhile #full { |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 143 | pub label: Option<Lifetime>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 144 | pub colon_token: Option<Token![:]>, |
| 145 | pub while_token: Token![while], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 146 | pub cond: Box<Expr>, |
| 147 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 148 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 149 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 150 | /// A while-let loop, with an optional label. |
| 151 | /// |
| 152 | /// E.g., `'label: while let pat = expr { block }` |
| 153 | /// |
| 154 | /// This is desugared to a combination of `loop` and `match` expressions. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 155 | pub WhileLet(ExprWhileLet #full { |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 156 | pub label: Option<Lifetime>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 157 | pub colon_token: Option<Token![:]>, |
| 158 | pub while_token: Token![while], |
| 159 | pub let_token: Token![let], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 160 | pub pat: Box<Pat>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 161 | pub eq_token: Token![=], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 162 | pub expr: Box<Expr>, |
| 163 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 164 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 165 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 166 | /// A for loop, with an optional label. |
| 167 | /// |
| 168 | /// E.g., `'label: for pat in expr { block }` |
| 169 | /// |
| 170 | /// This is desugared to a combination of `loop` and `match` expressions. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 171 | pub ForLoop(ExprForLoop #full { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 172 | pub label: Option<Lifetime>, |
| 173 | pub colon_token: Option<Token![:]>, |
| 174 | pub for_token: Token![for], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 175 | pub pat: Box<Pat>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 176 | pub in_token: Token![in], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 177 | pub expr: Box<Expr>, |
| 178 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 179 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 180 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 181 | /// Conditionless loop with an optional label. |
| 182 | /// |
| 183 | /// E.g. `'label: loop { block }` |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 184 | pub Loop(ExprLoop #full { |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 185 | pub label: Option<Lifetime>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 186 | pub colon_token: Option<Token![:]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 187 | pub loop_token: Token![loop], |
| 188 | pub body: Block, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 189 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 190 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 191 | /// A `match` block. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 192 | pub Match(ExprMatch #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 193 | pub match_token: Token![match], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 194 | pub expr: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 195 | pub brace_token: token::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 196 | pub arms: Vec<Arm>, |
| 197 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 198 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 199 | /// A closure (for example, `move |a, b, c| a + b + c`) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 200 | pub Closure(ExprClosure #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 201 | pub capture: CaptureBy, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 202 | pub or1_token: Token![|], |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 203 | pub inputs: Delimited<FnArg, Token![,]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 204 | pub or2_token: Token![|], |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 205 | pub output: ReturnType, |
| 206 | pub body: Box<Expr>, |
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 | |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 209 | /// An unsafe block (`unsafe { ... }`) |
| 210 | pub Unsafe(ExprUnsafe #full { |
| 211 | pub unsafe_token: Token![unsafe], |
| 212 | pub block: Block, |
| 213 | }), |
| 214 | |
| 215 | /// A block (`{ ... }`) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 216 | pub Block(ExprBlock #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 217 | pub block: Block, |
| 218 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 219 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 220 | /// An assignment (`a = foo()`) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 221 | pub Assign(ExprAssign #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 222 | pub left: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 223 | pub eq_token: Token![=], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 224 | pub right: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 225 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 226 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 227 | /// An assignment with an operator |
| 228 | /// |
| 229 | /// For example, `a += 1`. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 230 | pub AssignOp(ExprAssignOp #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 231 | pub left: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 232 | pub op: BinOp, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 233 | pub right: Box<Expr>, |
| 234 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 235 | |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 236 | /// Access of a named struct field (`obj.foo`) or unnamed tuple struct |
| 237 | /// field (`obj.0`). |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 238 | pub Field(ExprField #full { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 239 | pub base: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 240 | pub dot_token: Token![.], |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 241 | pub member: Member, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 242 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 243 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 244 | /// An indexing operation (`foo[2]`) |
| 245 | pub Index(ExprIndex { |
| 246 | pub expr: Box<Expr>, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 247 | pub bracket_token: token::Bracket, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 248 | pub index: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 249 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 250 | |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 251 | /// A range (`1..2`, `1..`, `..2`, `1..=2`, `..=2`) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 252 | pub Range(ExprRange #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 253 | pub from: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 254 | pub limits: RangeLimits, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 255 | pub to: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 256 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 257 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 258 | /// Variable reference, possibly containing `::` and/or type |
| 259 | /// parameters, e.g. foo::bar::<baz>. |
| 260 | /// |
| 261 | /// Optionally "qualified", |
| 262 | /// E.g. `<Vec<T> as SomeTrait>::SomeType`. |
| 263 | pub Path(ExprPath { |
| 264 | pub qself: Option<QSelf>, |
| 265 | pub path: Path, |
| 266 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 267 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 268 | /// A referencing operation (`&a` or `&mut a`) |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 269 | pub AddrOf(ExprAddrOf #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 270 | pub and_token: Token![&], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 271 | pub mutbl: Mutability, |
| 272 | pub expr: Box<Expr>, |
| 273 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 274 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 275 | /// A `break`, with an optional label to break, and an optional expression |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 276 | pub Break(ExprBreak #full { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 277 | pub break_token: Token![break], |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 278 | pub label: Option<Lifetime>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 279 | pub expr: Option<Box<Expr>>, |
| 280 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 281 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 282 | /// A `continue`, with an optional label |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 283 | pub Continue(ExprContinue #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 284 | pub continue_token: Token![continue], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 285 | pub label: Option<Lifetime>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 286 | }), |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 287 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 288 | /// A `return`, with an optional value to be returned |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 289 | pub Ret(ExprRet #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 290 | pub return_token: Token![return], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 291 | pub expr: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 292 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 293 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 294 | /// A macro invocation; pre-expansion |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 295 | pub Macro(Macro), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 296 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 297 | /// A struct literal expression. |
| 298 | /// |
| 299 | /// For example, `Foo {x: 1, y: 2}`, or |
| 300 | /// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 301 | pub Struct(ExprStruct #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 302 | pub path: Path, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 303 | pub brace_token: token::Brace, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 304 | pub fields: Delimited<FieldValue, Token![,]>, |
| 305 | pub dot2_token: Option<Token![..]>, |
| 306 | pub rest: Option<Box<Expr>>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 307 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 308 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 309 | /// An array literal constructed from one repeated element. |
| 310 | /// |
| 311 | /// For example, `[1; 5]`. The first expression is the element |
| 312 | /// to be repeated; the second is the number of times to repeat it. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 313 | pub Repeat(ExprRepeat #full { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 314 | pub bracket_token: token::Bracket, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 315 | pub expr: Box<Expr>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 316 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 317 | pub amt: Box<Expr>, |
| 318 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 319 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 320 | /// No-op: used solely so we can pretty-print faithfully |
| 321 | pub Paren(ExprParen { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 322 | pub paren_token: token::Paren, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 323 | pub expr: Box<Expr>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 324 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 325 | |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 326 | /// No-op: used solely so we can pretty-print faithfully |
| 327 | /// |
| 328 | /// A `group` represents a `None`-delimited span in the input |
| 329 | /// `TokenStream` which affects the precidence of the resulting |
| 330 | /// expression. They are used for macro hygiene. |
| 331 | pub Group(ExprGroup { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 332 | pub group_token: token::Group, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 333 | pub expr: Box<Expr>, |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 334 | }), |
| 335 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 336 | /// `expr?` |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 337 | pub Try(ExprTry #full { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 338 | pub expr: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 339 | pub question_token: Token![?], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 340 | }), |
Arnavion | 02ef13f | 2017-04-25 00:54:31 -0700 | [diff] [blame] | 341 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 342 | /// A catch expression. |
| 343 | /// |
| 344 | /// E.g. `do catch { block }` |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 345 | pub Catch(ExprCatch #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 346 | pub do_token: Token![do], |
| 347 | pub catch_token: Token![catch], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 348 | pub block: Block, |
| 349 | }), |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 350 | |
| 351 | /// A yield expression. |
| 352 | /// |
| 353 | /// E.g. `yield expr` |
| 354 | pub Yield(ExprYield #full { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 355 | pub yield_token: Token![yield], |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 356 | pub expr: Option<Box<Expr>>, |
| 357 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 358 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 361 | #[cfg(feature = "full")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 362 | ast_enum! { |
| 363 | /// A struct or tuple struct field accessed in a struct literal or field |
| 364 | /// expression. |
| 365 | pub enum Member { |
| 366 | /// A named field like `self.x`. |
| 367 | Named(Ident), |
| 368 | /// An unnamed field like `self.0`. |
| 369 | Unnamed(Index), |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | #[cfg(feature = "full")] |
| 374 | ast_struct! { |
| 375 | /// The index of an unnamed tuple struct field. |
| 376 | pub struct Index #manual_extra_traits { |
| 377 | pub index: u32, |
| 378 | pub span: Span, |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | #[cfg(feature = "full")] |
| 383 | impl Eq for Index {} |
| 384 | |
| 385 | #[cfg(feature = "full")] |
| 386 | impl PartialEq for Index { |
| 387 | fn eq(&self, other: &Self) -> bool { |
| 388 | self.index == other.index |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | #[cfg(feature = "full")] |
| 393 | impl Hash for Index { |
| 394 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 395 | self.index.hash(state); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 400 | ast_struct! { |
| 401 | /// A field-value pair in a struct literal. |
| 402 | pub struct FieldValue { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 403 | /// Attributes tagged on the field. |
| 404 | pub attrs: Vec<Attribute>, |
| 405 | |
| 406 | /// Name or index of the field. |
| 407 | pub member: Member, |
| 408 | |
| 409 | pub colon_token: Option<Token![:]>, |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 410 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 411 | /// Value of the field. |
| 412 | pub expr: Expr, |
Clar Charr | d22b570 | 2017-03-10 15:24:56 -0500 | [diff] [blame] | 413 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 414 | /// Whether this is a shorthand field, e.g. `Struct { x }` |
| 415 | /// instead of `Struct { x: x }`. |
| 416 | pub is_shorthand: bool, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 417 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 420 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 421 | ast_struct! { |
| 422 | /// A Block (`{ .. }`). |
| 423 | /// |
| 424 | /// E.g. `{ .. }` as in `fn foo() { .. }` |
| 425 | pub struct Block { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 426 | pub brace_token: token::Brace, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 427 | /// Statements in a block |
| 428 | pub stmts: Vec<Stmt>, |
| 429 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 432 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 433 | ast_enum! { |
| 434 | /// A statement, usually ending in a semicolon. |
| 435 | pub enum Stmt { |
| 436 | /// A local (let) binding. |
| 437 | Local(Box<Local>), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 438 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 439 | /// An item definition. |
| 440 | Item(Box<Item>), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 441 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 442 | /// Expr without trailing semicolon. |
| 443 | Expr(Box<Expr>), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 444 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 445 | /// Expression with trailing semicolon; |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 446 | Semi(Box<Expr>, Token![;]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 447 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 450 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 451 | ast_struct! { |
| 452 | /// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;` |
| 453 | pub struct Local { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 454 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 455 | pub let_token: Token![let], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 456 | pub pat: Box<Pat>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 457 | pub colon_token: Option<Token![:]>, |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 458 | pub ty: Option<Box<Type>>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 459 | pub eq_token: Option<Token![=]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 460 | /// Initializer expression to set the value, if any |
| 461 | pub init: Option<Box<Expr>>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 462 | pub semi_token: Token![;], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 463 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 466 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 467 | ast_enum_of_structs! { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 468 | // Clippy false positive |
| 469 | // https://github.com/Manishearth/rust-clippy/issues/1241 |
| 470 | #[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))] |
| 471 | pub enum Pat { |
| 472 | /// Represents a wildcard pattern (`_`) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 473 | pub Wild(PatWild { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 474 | pub underscore_token: Token![_], |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 475 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 476 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 477 | /// A `Pat::Ident` may either be a new bound variable (`ref mut binding @ OPT_SUBPATTERN`), |
| 478 | /// or a unit struct/variant pattern, or a const pattern (in the last two cases the third |
| 479 | /// field must be `None`). Disambiguation cannot be done with parser alone, so it happens |
| 480 | /// during name resolution. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 481 | pub Ident(PatIdent { |
| 482 | pub mode: BindingMode, |
| 483 | pub ident: Ident, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 484 | pub at_token: Option<Token![@]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 485 | pub subpat: Option<Box<Pat>>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 486 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 487 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 488 | /// A struct or struct variant pattern, e.g. `Variant {x, y, ..}`. |
| 489 | /// The `bool` is `true` in the presence of a `..`. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 490 | pub Struct(PatStruct { |
| 491 | pub path: Path, |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 492 | pub brace_token: token::Brace, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 493 | pub fields: Delimited<FieldPat, Token![,]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 494 | pub dot2_token: Option<Token![..]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 495 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 496 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 497 | /// A tuple struct/variant pattern `Variant(x, y, .., z)`. |
| 498 | /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position. |
| 499 | /// 0 <= position <= subpats.len() |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 500 | pub TupleStruct(PatTupleStruct { |
| 501 | pub path: Path, |
| 502 | pub pat: PatTuple, |
| 503 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 504 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 505 | /// A possibly qualified path pattern. |
| 506 | /// Unquailfied path patterns `A::B::C` can legally refer to variants, structs, constants |
| 507 | /// or associated constants. Quailfied path patterns `<A>::B::C`/`<A as Trait>::B::C` can |
| 508 | /// only legally refer to associated constants. |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 509 | pub Path(PatPath { |
| 510 | pub qself: Option<QSelf>, |
| 511 | pub path: Path, |
| 512 | }), |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 513 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 514 | /// A tuple pattern `(a, b)`. |
| 515 | /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position. |
| 516 | /// 0 <= position <= subpats.len() |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 517 | pub Tuple(PatTuple { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 518 | pub paren_token: token::Paren, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 519 | pub pats: Delimited<Pat, Token![,]>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 520 | pub comma_token: Option<Token![,]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 521 | pub dots_pos: Option<usize>, |
| 522 | pub dot2_token: Option<Token![..]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 523 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 524 | /// A `box` pattern |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 525 | pub Box(PatBox { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 526 | pub box_token: Token![box], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 527 | pub pat: Box<Pat>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 528 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 529 | /// A reference pattern, e.g. `&mut (a, b)` |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 530 | pub Ref(PatRef { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 531 | pub and_token: Token![&], |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 532 | pub mutbl: Mutability, |
| 533 | pub pat: Box<Pat>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 534 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 535 | /// A literal |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 536 | pub Lit(PatLit { |
| 537 | pub expr: Box<Expr>, |
| 538 | }), |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 539 | /// A range pattern, e.g. `1..=2` |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 540 | pub Range(PatRange { |
| 541 | pub lo: Box<Expr>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 542 | pub limits: RangeLimits, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 543 | pub hi: Box<Expr>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 544 | }), |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 545 | /// `[a, b, i.., y, z]` is represented as: |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 546 | pub Slice(PatSlice { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 547 | pub bracket_token: token::Bracket, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 548 | pub front: Delimited<Pat, Token![,]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 549 | pub middle: Option<Box<Pat>>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 550 | pub comma_token: Option<Token![,]>, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 551 | pub dot2_token: Option<Token![..]>, |
| 552 | pub back: Delimited<Pat, Token![,]>, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 553 | }), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 554 | /// A macro pattern; pre-expansion |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 555 | pub Macro(Macro), |
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 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 559 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 560 | ast_struct! { |
| 561 | /// An arm of a 'match'. |
| 562 | /// |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 563 | /// E.g. `0..=10 => { println!("match!") }` as in |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 564 | /// |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 565 | /// ```rust |
| 566 | /// # #![feature(dotdoteq_in_patterns)] |
| 567 | /// # |
| 568 | /// # fn main() { |
| 569 | /// # let n = 0; |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 570 | /// match n { |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 571 | /// 0..=10 => { println!("match!") } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 572 | /// // .. |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 573 | /// # _ => {} |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 574 | /// } |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 575 | /// # } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 576 | /// ``` |
| 577 | pub struct Arm { |
| 578 | pub attrs: Vec<Attribute>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 579 | pub pats: Delimited<Pat, Token![|]>, |
| 580 | pub if_token: Option<Token![if]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 581 | pub guard: Option<Box<Expr>>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 582 | pub rocket_token: Token![=>], |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 583 | pub body: Box<Expr>, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 584 | pub comma: Option<Token![,]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 585 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 588 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 589 | ast_enum! { |
| 590 | /// A capture clause |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 591 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 592 | pub enum CaptureBy { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 593 | Value(Token![move]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 594 | Ref, |
| 595 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 598 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 599 | ast_enum! { |
| 600 | /// Limit types of a range (inclusive or exclusive) |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 601 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 602 | pub enum RangeLimits { |
| 603 | /// Inclusive at the beginning, exclusive at the end |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 604 | HalfOpen(Token![..]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 605 | /// Inclusive at the beginning and end |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 606 | Closed(Token![..=]), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 607 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 610 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 611 | ast_struct! { |
| 612 | /// A single field in a struct pattern |
| 613 | /// |
| 614 | /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` |
| 615 | /// are treated the same as `x: x, y: ref y, z: ref mut z`, |
| 616 | /// except `is_shorthand` is true |
| 617 | pub struct FieldPat { |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 618 | pub attrs: Vec<Attribute>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 619 | /// The identifier for the field |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 620 | pub member: Member, |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 621 | pub colon_token: Option<Token![:]>, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 622 | /// The pattern the field is destructured to |
| 623 | pub pat: Box<Pat>, |
| 624 | pub is_shorthand: bool, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 625 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 628 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 629 | ast_enum! { |
Alex Crichton | 2e0229c | 2017-05-23 09:34:50 -0700 | [diff] [blame] | 630 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 631 | pub enum BindingMode { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 632 | ByRef(Token![ref], Mutability), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 633 | ByValue(Mutability), |
| 634 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 637 | #[cfg(feature = "full")] |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 638 | ast_enum! { |
| 639 | #[cfg_attr(feature = "clone-impls", derive(Copy))] |
| 640 | pub enum InPlaceKind { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 641 | Arrow(Token![<-]), |
| 642 | In(Token![in]), |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 643 | } |
| 644 | } |
| 645 | |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 646 | #[cfg(any(feature = "parsing", feature = "printing"))] |
| 647 | #[cfg(feature = "full")] |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 648 | fn arm_expr_requires_comma(expr: &Expr) -> bool { |
| 649 | // see https://github.com/rust-lang/rust/blob/eb8f2586e |
| 650 | // /src/libsyntax/parse/classify.rs#L17-L37 |
| 651 | match expr.node { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 652 | ExprKind::Unsafe(..) |
| 653 | | ExprKind::Block(..) |
| 654 | | ExprKind::If(..) |
| 655 | | ExprKind::IfLet(..) |
| 656 | | ExprKind::Match(..) |
| 657 | | ExprKind::While(..) |
| 658 | | ExprKind::WhileLet(..) |
| 659 | | ExprKind::Loop(..) |
| 660 | | ExprKind::ForLoop(..) |
| 661 | | ExprKind::Catch(..) => false, |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 662 | _ => true, |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 666 | #[cfg(feature = "parsing")] |
| 667 | pub mod parsing { |
| 668 | use super::*; |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 669 | use ty::parsing::qpath; |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 670 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 671 | #[cfg(feature = "full")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 672 | use proc_macro2::{Delimiter, Span, TokenNode, TokenStream}; |
David Tolnay | c5ab8c6 | 2017-12-26 16:43:39 -0500 | [diff] [blame] | 673 | use synom::Synom; |
| 674 | use cursor::Cursor; |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 675 | #[cfg(feature = "full")] |
David Tolnay | c5ab8c6 | 2017-12-26 16:43:39 -0500 | [diff] [blame] | 676 | use parse_error; |
David Tolnay | 203557a | 2017-12-27 23:59:33 -0500 | [diff] [blame] | 677 | use synom::PResult; |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 678 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 679 | // When we're parsing expressions which occur before blocks, like in an if |
| 680 | // statement's condition, we cannot parse a struct literal. |
| 681 | // |
| 682 | // Struct literals are ambiguous in certain positions |
| 683 | // https://github.com/rust-lang/rfcs/pull/92 |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 684 | macro_rules! ambiguous_expr { |
| 685 | ($i:expr, $allow_struct:ident) => { |
David Tolnay | 54e854d | 2016-10-24 12:03:30 -0700 | [diff] [blame] | 686 | ambiguous_expr($i, $allow_struct, true) |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 687 | }; |
| 688 | } |
| 689 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 690 | // When we are parsing an optional suffix expression, we cannot allow blocks |
| 691 | // if structs are not allowed. |
| 692 | // |
| 693 | // Example: |
| 694 | // |
| 695 | // if break {} {} |
| 696 | // |
| 697 | // is ambiguous between: |
| 698 | // |
| 699 | // if (break {}) {} |
| 700 | // if (break) {} {} |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 701 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 702 | macro_rules! opt_ambiguous_expr { |
| 703 | ($i:expr, $allow_struct:ident) => { |
| 704 | option!($i, call!(ambiguous_expr, $allow_struct, $allow_struct)) |
| 705 | }; |
| 706 | } |
| 707 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 708 | impl Synom for Expr { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 709 | named!(parse -> Self, ambiguous_expr!(true)); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 710 | |
| 711 | fn description() -> Option<&'static str> { |
| 712 | Some("expression") |
| 713 | } |
| 714 | } |
| 715 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 716 | #[cfg(feature = "full")] |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 717 | named!(expr_no_struct -> Expr, ambiguous_expr!(false)); |
| 718 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 719 | // Parse an arbitrary expression. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 720 | #[cfg(feature = "full")] |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 721 | fn ambiguous_expr(i: Cursor, allow_struct: bool, allow_block: bool) -> PResult<Expr> { |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 722 | map!( |
David Tolnay | 54e854d | 2016-10-24 12:03:30 -0700 | [diff] [blame] | 723 | i, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 724 | call!(assign_expr, allow_struct, allow_block), |
| 725 | ExprKind::into |
| 726 | ) |
| 727 | } |
| 728 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 729 | #[cfg(not(feature = "full"))] |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 730 | fn ambiguous_expr(i: Cursor, allow_struct: bool, allow_block: bool) -> PResult<Expr> { |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 731 | map!( |
| 732 | i, |
| 733 | // NOTE: We intentionally skip assign_expr, placement_expr, and |
| 734 | // range_expr, as they are not parsed in non-full mode. |
| 735 | call!(or_expr, allow_struct, allow_block), |
| 736 | ExprKind::into |
| 737 | ) |
| 738 | } |
| 739 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 740 | // Parse a left-associative binary operator. |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 741 | macro_rules! binop { |
| 742 | ( |
| 743 | $name: ident, |
| 744 | $next: ident, |
| 745 | $submac: ident!( $($args:tt)* ) |
| 746 | ) => { |
| 747 | named!($name(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 748 | mut e: call!($next, allow_struct, allow_block) >> |
| 749 | many0!(do_parse!( |
| 750 | op: $submac!($($args)*) >> |
| 751 | rhs: call!($next, allow_struct, true) >> |
| 752 | ({ |
| 753 | e = ExprBinary { |
| 754 | left: Box::new(e.into()), |
| 755 | op: op, |
| 756 | right: Box::new(rhs.into()), |
| 757 | }.into(); |
| 758 | }) |
| 759 | )) >> |
| 760 | (e) |
| 761 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 762 | } |
David Tolnay | 54e854d | 2016-10-24 12:03:30 -0700 | [diff] [blame] | 763 | } |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 764 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 765 | // <placement> = <placement> .. |
| 766 | // <placement> += <placement> .. |
| 767 | // <placement> -= <placement> .. |
| 768 | // <placement> *= <placement> .. |
| 769 | // <placement> /= <placement> .. |
| 770 | // <placement> %= <placement> .. |
| 771 | // <placement> ^= <placement> .. |
| 772 | // <placement> &= <placement> .. |
| 773 | // <placement> |= <placement> .. |
| 774 | // <placement> <<= <placement> .. |
| 775 | // <placement> >>= <placement> .. |
| 776 | // |
| 777 | // NOTE: This operator is right-associative. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 778 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 779 | named!(assign_expr(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 780 | mut e: call!(placement_expr, allow_struct, allow_block) >> |
| 781 | alt!( |
| 782 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 783 | eq: punct!(=) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 784 | // Recurse into self to parse right-associative operator. |
| 785 | rhs: call!(assign_expr, allow_struct, true) >> |
| 786 | ({ |
| 787 | e = ExprAssign { |
| 788 | left: Box::new(e.into()), |
| 789 | eq_token: eq, |
| 790 | right: Box::new(rhs.into()), |
| 791 | }.into(); |
| 792 | }) |
| 793 | ) |
| 794 | | |
| 795 | do_parse!( |
| 796 | op: call!(BinOp::parse_assign_op) >> |
| 797 | // Recurse into self to parse right-associative operator. |
| 798 | rhs: call!(assign_expr, allow_struct, true) >> |
| 799 | ({ |
| 800 | e = ExprAssignOp { |
| 801 | left: Box::new(e.into()), |
| 802 | op: op, |
| 803 | right: Box::new(rhs.into()), |
| 804 | }.into(); |
| 805 | }) |
| 806 | ) |
| 807 | | |
| 808 | epsilon!() |
| 809 | ) >> |
| 810 | (e) |
| 811 | )); |
| 812 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 813 | // <range> <- <range> .. |
| 814 | // |
| 815 | // NOTE: The `in place { expr }` version of this syntax is parsed in |
| 816 | // `atom_expr`, not here. |
| 817 | // |
| 818 | // NOTE: This operator is right-associative. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 819 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 820 | named!(placement_expr(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 821 | mut e: call!(range_expr, allow_struct, allow_block) >> |
| 822 | alt!( |
| 823 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 824 | arrow: punct!(<-) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 825 | // Recurse into self to parse right-associative operator. |
| 826 | rhs: call!(placement_expr, allow_struct, true) >> |
| 827 | ({ |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 828 | e = ExprInPlace { |
| 829 | // op: BinOp::Place(larrow), |
| 830 | place: Box::new(e.into()), |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 831 | kind: InPlaceKind::Arrow(arrow), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 832 | value: Box::new(rhs.into()), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 833 | }.into(); |
| 834 | }) |
| 835 | ) |
| 836 | | |
| 837 | epsilon!() |
| 838 | ) >> |
| 839 | (e) |
| 840 | )); |
| 841 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 842 | // <or> ... <or> .. |
| 843 | // <or> .. <or> .. |
| 844 | // <or> .. |
| 845 | // |
| 846 | // NOTE: This is currently parsed oddly - I'm not sure of what the exact |
| 847 | // rules are for parsing these expressions are, but this is not correct. |
| 848 | // For example, `a .. b .. c` is not a legal expression. It should not |
| 849 | // be parsed as either `(a .. b) .. c` or `a .. (b .. c)` apparently. |
| 850 | // |
| 851 | // NOTE: The form of ranges which don't include a preceding expression are |
| 852 | // parsed by `atom_expr`, rather than by this function. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 853 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 854 | named!(range_expr(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 855 | mut e: call!(or_expr, allow_struct, allow_block) >> |
| 856 | many0!(do_parse!( |
| 857 | limits: syn!(RangeLimits) >> |
| 858 | // We don't want to allow blocks here if we don't allow structs. See |
| 859 | // the reasoning for `opt_ambiguous_expr!` above. |
| 860 | hi: option!(call!(or_expr, allow_struct, allow_struct)) >> |
| 861 | ({ |
| 862 | e = ExprRange { |
| 863 | from: Some(Box::new(e.into())), |
| 864 | limits: limits, |
| 865 | to: hi.map(|e| Box::new(e.into())), |
| 866 | }.into(); |
| 867 | }) |
| 868 | )) >> |
| 869 | (e) |
| 870 | )); |
| 871 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 872 | // <and> || <and> ... |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 873 | binop!(or_expr, and_expr, map!(punct!(||), BinOp::Or)); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 874 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 875 | // <compare> && <compare> ... |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 876 | binop!(and_expr, compare_expr, map!(punct!(&&), BinOp::And)); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 877 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 878 | // <bitor> == <bitor> ... |
| 879 | // <bitor> != <bitor> ... |
| 880 | // <bitor> >= <bitor> ... |
| 881 | // <bitor> <= <bitor> ... |
| 882 | // <bitor> > <bitor> ... |
| 883 | // <bitor> < <bitor> ... |
| 884 | // |
| 885 | // NOTE: This operator appears to be parsed as left-associative, but errors |
| 886 | // if it is used in a non-associative manner. |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 887 | binop!( |
| 888 | compare_expr, |
| 889 | bitor_expr, |
| 890 | alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 891 | punct!(==) => { BinOp::Eq } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 892 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 893 | punct!(!=) => { BinOp::Ne } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 894 | | |
| 895 | // must be above Lt |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 896 | punct!(<=) => { BinOp::Le } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 897 | | |
| 898 | // must be above Gt |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 899 | punct!(>=) => { BinOp::Ge } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 900 | | |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 901 | do_parse!( |
| 902 | // Make sure that we don't eat the < part of a <- operator |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 903 | not!(punct!(<-)) >> |
| 904 | t: punct!(<) >> |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 905 | (BinOp::Lt(t)) |
| 906 | ) |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 907 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 908 | punct!(>) => { BinOp::Gt } |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 909 | ) |
| 910 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 911 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 912 | // <bitxor> | <bitxor> ... |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 913 | binop!( |
| 914 | bitor_expr, |
| 915 | bitxor_expr, |
| 916 | do_parse!(not!(punct!(||)) >> not!(punct!(|=)) >> t: punct!(|) >> (BinOp::BitOr(t))) |
| 917 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 918 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 919 | // <bitand> ^ <bitand> ... |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 920 | binop!( |
| 921 | bitxor_expr, |
| 922 | bitand_expr, |
| 923 | do_parse!( |
| 924 | // NOTE: Make sure we aren't looking at ^=. |
| 925 | not!(punct!(^=)) >> t: punct!(^) >> (BinOp::BitXor(t)) |
| 926 | ) |
| 927 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 928 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 929 | // <shift> & <shift> ... |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 930 | binop!( |
| 931 | bitand_expr, |
| 932 | shift_expr, |
| 933 | do_parse!( |
| 934 | // NOTE: Make sure we aren't looking at && or &=. |
| 935 | not!(punct!(&&)) >> not!(punct!(&=)) >> t: punct!(&) >> (BinOp::BitAnd(t)) |
| 936 | ) |
| 937 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 938 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 939 | // <arith> << <arith> ... |
| 940 | // <arith> >> <arith> ... |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 941 | binop!( |
| 942 | shift_expr, |
| 943 | arith_expr, |
| 944 | alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 945 | punct!(<<) => { BinOp::Shl } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 946 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 947 | punct!(>>) => { BinOp::Shr } |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 948 | ) |
| 949 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 950 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 951 | // <term> + <term> ... |
| 952 | // <term> - <term> ... |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 953 | binop!( |
| 954 | arith_expr, |
| 955 | term_expr, |
| 956 | alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 957 | punct!(+) => { BinOp::Add } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 958 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 959 | punct!(-) => { BinOp::Sub } |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 960 | ) |
| 961 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 962 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 963 | // <cast> * <cast> ... |
| 964 | // <cast> / <cast> ... |
| 965 | // <cast> % <cast> ... |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 966 | binop!( |
| 967 | term_expr, |
| 968 | cast_expr, |
| 969 | alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 970 | punct!(*) => { BinOp::Mul } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 971 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 972 | punct!(/) => { BinOp::Div } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 973 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 974 | punct!(%) => { BinOp::Rem } |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 975 | ) |
| 976 | ); |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 977 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 978 | // <unary> as <ty> |
| 979 | // <unary> : <ty> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 980 | named!(cast_expr(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 981 | mut e: call!(unary_expr, allow_struct, allow_block) >> |
| 982 | many0!(alt!( |
| 983 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 984 | as_: keyword!(as) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 985 | // We can't accept `A + B` in cast expressions, as it's |
| 986 | // ambiguous with the + expression. |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 987 | ty: call!(Type::without_plus) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 988 | ({ |
| 989 | e = ExprCast { |
| 990 | expr: Box::new(e.into()), |
| 991 | as_token: as_, |
| 992 | ty: Box::new(ty), |
| 993 | }.into(); |
| 994 | }) |
| 995 | ) |
| 996 | | |
| 997 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 998 | colon: punct!(:) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 999 | // We can't accept `A + B` in cast expressions, as it's |
| 1000 | // ambiguous with the + expression. |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1001 | ty: call!(Type::without_plus) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1002 | ({ |
| 1003 | e = ExprType { |
| 1004 | expr: Box::new(e.into()), |
| 1005 | colon_token: colon, |
| 1006 | ty: Box::new(ty), |
| 1007 | }.into(); |
| 1008 | }) |
| 1009 | ) |
| 1010 | )) >> |
| 1011 | (e) |
| 1012 | )); |
| 1013 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1014 | // <UnOp> <trailer> |
| 1015 | // & <trailer> |
| 1016 | // &mut <trailer> |
| 1017 | // box <trailer> |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1018 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1019 | named!(unary_expr(allow_struct: bool, allow_block: bool) -> ExprKind, alt!( |
| 1020 | do_parse!( |
| 1021 | op: syn!(UnOp) >> |
| 1022 | expr: call!(unary_expr, allow_struct, true) >> |
| 1023 | (ExprUnary { |
| 1024 | op: op, |
| 1025 | expr: Box::new(expr.into()), |
| 1026 | }.into()) |
| 1027 | ) |
| 1028 | | |
| 1029 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1030 | and: punct!(&) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1031 | mutability: syn!(Mutability) >> |
| 1032 | expr: call!(unary_expr, allow_struct, true) >> |
| 1033 | (ExprAddrOf { |
| 1034 | and_token: and, |
| 1035 | mutbl: mutability, |
| 1036 | expr: Box::new(expr.into()), |
| 1037 | }.into()) |
| 1038 | ) |
| 1039 | | |
| 1040 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1041 | box_: keyword!(box) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1042 | expr: call!(unary_expr, allow_struct, true) >> |
| 1043 | (ExprBox { |
| 1044 | box_token: box_, |
| 1045 | expr: Box::new(expr.into()), |
| 1046 | }.into()) |
| 1047 | ) |
| 1048 | | |
| 1049 | call!(trailer_expr, allow_struct, allow_block) |
| 1050 | )); |
| 1051 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1052 | // XXX: This duplication is ugly |
| 1053 | #[cfg(not(feature = "full"))] |
| 1054 | named!(unary_expr(allow_struct: bool, allow_block: bool) -> ExprKind, alt!( |
| 1055 | do_parse!( |
| 1056 | op: syn!(UnOp) >> |
| 1057 | expr: call!(unary_expr, allow_struct, true) >> |
| 1058 | (ExprUnary { |
| 1059 | op: op, |
| 1060 | expr: Box::new(expr.into()), |
| 1061 | }.into()) |
| 1062 | ) |
| 1063 | | |
| 1064 | call!(trailer_expr, allow_struct, allow_block) |
| 1065 | )); |
| 1066 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1067 | // <atom> (..<args>) ... |
| 1068 | // <atom> . <ident> (..<args>) ... |
| 1069 | // <atom> . <ident> ... |
| 1070 | // <atom> . <lit> ... |
| 1071 | // <atom> [ <expr> ] ... |
| 1072 | // <atom> ? ... |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1073 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1074 | named!(trailer_expr(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 1075 | mut e: call!(atom_expr, allow_struct, allow_block) >> |
| 1076 | many0!(alt!( |
| 1077 | tap!(args: and_call => { |
| 1078 | let (args, paren) = args; |
| 1079 | e = ExprCall { |
| 1080 | func: Box::new(e.into()), |
| 1081 | args: args, |
| 1082 | paren_token: paren, |
| 1083 | }.into(); |
| 1084 | }) |
| 1085 | | |
| 1086 | tap!(more: and_method_call => { |
| 1087 | let mut call = more; |
| 1088 | call.expr = Box::new(e.into()); |
| 1089 | e = call.into(); |
| 1090 | }) |
| 1091 | | |
| 1092 | tap!(field: and_field => { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1093 | let (token, member) = field; |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1094 | e = ExprField { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1095 | base: Box::new(e.into()), |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1096 | dot_token: token, |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1097 | member: member, |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1098 | }.into(); |
| 1099 | }) |
| 1100 | | |
| 1101 | tap!(i: and_index => { |
| 1102 | let (i, token) = i; |
| 1103 | e = ExprIndex { |
| 1104 | expr: Box::new(e.into()), |
| 1105 | bracket_token: token, |
| 1106 | index: Box::new(i), |
| 1107 | }.into(); |
| 1108 | }) |
| 1109 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1110 | tap!(question: punct!(?) => { |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1111 | e = ExprTry { |
| 1112 | expr: Box::new(e.into()), |
| 1113 | question_token: question, |
| 1114 | }.into(); |
| 1115 | }) |
| 1116 | )) >> |
| 1117 | (e) |
| 1118 | )); |
| 1119 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1120 | // XXX: Duplication == ugly |
| 1121 | #[cfg(not(feature = "full"))] |
| 1122 | named!(trailer_expr(allow_struct: bool, allow_block: bool) -> ExprKind, do_parse!( |
| 1123 | mut e: call!(atom_expr, allow_struct, allow_block) >> |
| 1124 | many0!(alt!( |
| 1125 | tap!(args: and_call => { |
| 1126 | let (args, paren) = args; |
| 1127 | e = ExprCall { |
| 1128 | func: Box::new(e.into()), |
| 1129 | args: args, |
| 1130 | paren_token: paren, |
| 1131 | }.into(); |
| 1132 | }) |
| 1133 | | |
| 1134 | tap!(i: and_index => { |
| 1135 | let (i, token) = i; |
| 1136 | e = ExprIndex { |
| 1137 | expr: Box::new(e.into()), |
| 1138 | bracket_token: token, |
| 1139 | index: Box::new(i), |
| 1140 | }.into(); |
| 1141 | }) |
| 1142 | )) >> |
| 1143 | (e) |
| 1144 | )); |
| 1145 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1146 | // Parse all atomic expressions which don't have to worry about precidence |
| 1147 | // interactions, as they are fully contained. |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1148 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1149 | named!(atom_expr(allow_struct: bool, allow_block: bool) -> ExprKind, alt!( |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1150 | syn!(ExprGroup) => { ExprKind::Group } // must be placed first |
| 1151 | | |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1152 | syn!(Lit) => { ExprKind::Lit } // must be before expr_struct |
| 1153 | | |
| 1154 | // must be before expr_path |
| 1155 | cond_reduce!(allow_struct, map!(syn!(ExprStruct), ExprKind::Struct)) |
| 1156 | | |
| 1157 | syn!(ExprParen) => { ExprKind::Paren } // must be before expr_tup |
| 1158 | | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1159 | syn!(Macro) => { ExprKind::Macro } // must be before expr_path |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1160 | | |
| 1161 | call!(expr_break, allow_struct) // must be before expr_path |
| 1162 | | |
| 1163 | syn!(ExprContinue) => { ExprKind::Continue } // must be before expr_path |
| 1164 | | |
| 1165 | call!(expr_ret, allow_struct) // must be before expr_path |
| 1166 | | |
| 1167 | // NOTE: The `in place { expr }` form. `place <- expr` is parsed above. |
| 1168 | syn!(ExprInPlace) => { ExprKind::InPlace } |
| 1169 | | |
| 1170 | syn!(ExprArray) => { ExprKind::Array } |
| 1171 | | |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 1172 | syn!(ExprTuple) => { ExprKind::Tuple } |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1173 | | |
| 1174 | syn!(ExprIf) => { ExprKind::If } |
| 1175 | | |
| 1176 | syn!(ExprIfLet) => { ExprKind::IfLet } |
| 1177 | | |
| 1178 | syn!(ExprWhile) => { ExprKind::While } |
| 1179 | | |
| 1180 | syn!(ExprWhileLet) => { ExprKind::WhileLet } |
| 1181 | | |
| 1182 | syn!(ExprForLoop) => { ExprKind::ForLoop } |
| 1183 | | |
| 1184 | syn!(ExprLoop) => { ExprKind::Loop } |
| 1185 | | |
| 1186 | syn!(ExprMatch) => { ExprKind::Match } |
| 1187 | | |
| 1188 | syn!(ExprCatch) => { ExprKind::Catch } |
| 1189 | | |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 1190 | syn!(ExprYield) => { ExprKind::Yield } |
| 1191 | | |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 1192 | syn!(ExprUnsafe) => { ExprKind::Unsafe } |
| 1193 | | |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1194 | call!(expr_closure, allow_struct) |
| 1195 | | |
| 1196 | cond_reduce!(allow_block, map!(syn!(ExprBlock), ExprKind::Block)) |
| 1197 | | |
| 1198 | // NOTE: This is the prefix-form of range |
| 1199 | call!(expr_range, allow_struct) |
| 1200 | | |
| 1201 | syn!(ExprPath) => { ExprKind::Path } |
| 1202 | | |
| 1203 | syn!(ExprRepeat) => { ExprKind::Repeat } |
| 1204 | )); |
| 1205 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1206 | #[cfg(not(feature = "full"))] |
| 1207 | named!(atom_expr(_allow_struct: bool, _allow_block: bool) -> ExprKind, alt!( |
| 1208 | syn!(ExprGroup) => { ExprKind::Group } // must be placed first |
| 1209 | | |
| 1210 | syn!(Lit) => { ExprKind::Lit } // must be before expr_struct |
| 1211 | | |
| 1212 | syn!(ExprParen) => { ExprKind::Paren } // must be before expr_tup |
| 1213 | | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1214 | syn!(Macro) => { ExprKind::Macro } // must be before expr_path |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1215 | | |
| 1216 | syn!(ExprPath) => { ExprKind::Path } |
| 1217 | )); |
| 1218 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1219 | #[cfg(feature = "full")] |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1220 | named!(expr_nosemi -> Expr, map!(alt!( |
| 1221 | syn!(ExprIf) => { ExprKind::If } |
| 1222 | | |
| 1223 | syn!(ExprIfLet) => { ExprKind::IfLet } |
| 1224 | | |
| 1225 | syn!(ExprWhile) => { ExprKind::While } |
| 1226 | | |
| 1227 | syn!(ExprWhileLet) => { ExprKind::WhileLet } |
| 1228 | | |
| 1229 | syn!(ExprForLoop) => { ExprKind::ForLoop } |
| 1230 | | |
| 1231 | syn!(ExprLoop) => { ExprKind::Loop } |
| 1232 | | |
| 1233 | syn!(ExprMatch) => { ExprKind::Match } |
| 1234 | | |
| 1235 | syn!(ExprCatch) => { ExprKind::Catch } |
| 1236 | | |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 1237 | syn!(ExprYield) => { ExprKind::Yield } |
| 1238 | | |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 1239 | syn!(ExprUnsafe) => { ExprKind::Unsafe } |
| 1240 | | |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1241 | syn!(ExprBlock) => { ExprKind::Block } |
| 1242 | ), Expr::from)); |
| 1243 | |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1244 | impl Synom for ExprGroup { |
| 1245 | named!(parse -> Self, do_parse!( |
| 1246 | e: grouped!(syn!(Expr)) >> |
| 1247 | (ExprGroup { |
| 1248 | expr: Box::new(e.0), |
| 1249 | group_token: e.1, |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 1250 | }) |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 1251 | )); |
| 1252 | } |
| 1253 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1254 | impl Synom for ExprParen { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1255 | named!(parse -> Self, do_parse!( |
| 1256 | e: parens!(syn!(Expr)) >> |
| 1257 | (ExprParen { |
| 1258 | expr: Box::new(e.0), |
| 1259 | paren_token: e.1, |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 1260 | }) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1261 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1262 | } |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1263 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1264 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1265 | impl Synom for ExprInPlace { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1266 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1267 | in_: keyword!(in) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1268 | place: expr_no_struct >> |
| 1269 | value: braces!(call!(Block::parse_within)) >> |
| 1270 | (ExprInPlace { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1271 | place: Box::new(place), |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 1272 | kind: InPlaceKind::In(in_), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1273 | value: Box::new(Expr { |
| 1274 | node: ExprBlock { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1275 | block: Block { |
| 1276 | stmts: value.0, |
| 1277 | brace_token: value.1, |
| 1278 | }, |
| 1279 | }.into(), |
| 1280 | attrs: Vec::new(), |
| 1281 | }), |
| 1282 | }) |
| 1283 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1284 | } |
David Tolnay | 6696c3e | 2016-10-30 11:45:10 -0700 | [diff] [blame] | 1285 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1286 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1287 | impl Synom for ExprArray { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1288 | named!(parse -> Self, do_parse!( |
| 1289 | elems: brackets!(call!(Delimited::parse_terminated)) >> |
| 1290 | (ExprArray { |
| 1291 | exprs: elems.0, |
| 1292 | bracket_token: elems.1, |
| 1293 | }) |
| 1294 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1295 | } |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1296 | |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 1297 | named!(and_call -> (Delimited<Expr, Token![,]>, token::Paren), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1298 | parens!(call!(Delimited::parse_terminated))); |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1299 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1300 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1301 | named!(and_method_call -> ExprMethodCall, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1302 | dot: punct!(.) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1303 | method: syn!(Ident) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1304 | typarams: option!(do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1305 | colon2: punct!(::) >> |
| 1306 | lt: punct!(<) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1307 | tys: call!(Delimited::parse_terminated) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1308 | gt: punct!(>) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1309 | (colon2, lt, tys, gt) |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1310 | )) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1311 | args: parens!(call!(Delimited::parse_terminated)) >> |
| 1312 | ({ |
| 1313 | let (colon2, lt, tys, gt) = match typarams { |
| 1314 | Some((a, b, c, d)) => (Some(a), Some(b), Some(c), Some(d)), |
| 1315 | None => (None, None, None, None), |
| 1316 | }; |
| 1317 | ExprMethodCall { |
| 1318 | // this expr will get overwritten after being returned |
| 1319 | expr: Box::new(ExprKind::Lit(Lit { |
| 1320 | span: Span::default(), |
| 1321 | value: LitKind::Bool(false), |
| 1322 | }).into()), |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1323 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1324 | method: method, |
| 1325 | args: args.0, |
| 1326 | paren_token: args.1, |
| 1327 | dot_token: dot, |
| 1328 | lt_token: lt, |
| 1329 | gt_token: gt, |
| 1330 | colon2_token: colon2, |
| 1331 | typarams: tys.unwrap_or_default(), |
| 1332 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1333 | }) |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1334 | )); |
| 1335 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1336 | #[cfg(feature = "full")] |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 1337 | impl Synom for ExprTuple { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1338 | named!(parse -> Self, do_parse!( |
| 1339 | elems: parens!(call!(Delimited::parse_terminated)) >> |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 1340 | (ExprTuple { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1341 | args: elems.0, |
| 1342 | paren_token: elems.1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1343 | }) |
| 1344 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1345 | } |
David Tolnay | fa0edf2 | 2016-09-23 22:58:24 -0700 | [diff] [blame] | 1346 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1347 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1348 | impl Synom for ExprIfLet { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1349 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1350 | if_: keyword!(if) >> |
| 1351 | let_: keyword!(let) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1352 | pat: syn!(Pat) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1353 | eq: punct!(=) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1354 | cond: expr_no_struct >> |
| 1355 | then_block: braces!(call!(Block::parse_within)) >> |
| 1356 | else_block: option!(else_block) >> |
| 1357 | (ExprIfLet { |
| 1358 | pat: Box::new(pat), |
| 1359 | let_token: let_, |
| 1360 | eq_token: eq, |
| 1361 | expr: Box::new(cond), |
| 1362 | if_true: Block { |
| 1363 | stmts: then_block.0, |
| 1364 | brace_token: then_block.1, |
| 1365 | }, |
| 1366 | if_token: if_, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1367 | else_token: else_block.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1368 | if_false: else_block.map(|p| Box::new(p.1.into())), |
| 1369 | }) |
| 1370 | )); |
David Tolnay | 29f9ce1 | 2016-10-02 20:58:40 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1373 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1374 | impl Synom for ExprIf { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1375 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1376 | if_: keyword!(if) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1377 | cond: expr_no_struct >> |
| 1378 | then_block: braces!(call!(Block::parse_within)) >> |
| 1379 | else_block: option!(else_block) >> |
| 1380 | (ExprIf { |
| 1381 | cond: Box::new(cond), |
| 1382 | if_true: Block { |
| 1383 | stmts: then_block.0, |
| 1384 | brace_token: then_block.1, |
| 1385 | }, |
| 1386 | if_token: if_, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1387 | else_token: else_block.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1388 | if_false: else_block.map(|p| Box::new(p.1.into())), |
| 1389 | }) |
| 1390 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1391 | } |
David Tolnay | bb6feae | 2016-10-02 21:25:20 -0700 | [diff] [blame] | 1392 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1393 | #[cfg(feature = "full")] |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1394 | named!(else_block -> (Token![else], ExprKind), do_parse!( |
| 1395 | else_: keyword!(else) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1396 | expr: alt!( |
| 1397 | syn!(ExprIf) => { ExprKind::If } |
| 1398 | | |
| 1399 | syn!(ExprIfLet) => { ExprKind::IfLet } |
| 1400 | | |
| 1401 | do_parse!( |
| 1402 | else_block: braces!(call!(Block::parse_within)) >> |
| 1403 | (ExprKind::Block(ExprBlock { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1404 | block: Block { |
| 1405 | stmts: else_block.0, |
| 1406 | brace_token: else_block.1, |
| 1407 | }, |
| 1408 | })) |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1409 | ) |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1410 | ) >> |
| 1411 | (else_, expr) |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1412 | )); |
| 1413 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1414 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1415 | impl Synom for ExprForLoop { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1416 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1417 | lbl: option!(tuple!(syn!(Lifetime), punct!(:))) >> |
| 1418 | for_: keyword!(for) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1419 | pat: syn!(Pat) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1420 | in_: keyword!(in) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1421 | expr: expr_no_struct >> |
| 1422 | loop_block: syn!(Block) >> |
| 1423 | (ExprForLoop { |
| 1424 | for_token: for_, |
| 1425 | in_token: in_, |
| 1426 | pat: Box::new(pat), |
| 1427 | expr: Box::new(expr), |
| 1428 | body: loop_block, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1429 | colon_token: lbl.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1430 | label: lbl.map(|p| p.0), |
| 1431 | }) |
| 1432 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1433 | } |
Gregory Katz | e5f3568 | 2016-09-27 14:20:55 -0400 | [diff] [blame] | 1434 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1435 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1436 | impl Synom for ExprLoop { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1437 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1438 | lbl: option!(tuple!(syn!(Lifetime), punct!(:))) >> |
| 1439 | loop_: keyword!(loop) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1440 | loop_block: syn!(Block) >> |
| 1441 | (ExprLoop { |
| 1442 | loop_token: loop_, |
| 1443 | body: loop_block, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1444 | colon_token: lbl.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1445 | label: lbl.map(|p| p.0), |
| 1446 | }) |
| 1447 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1450 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1451 | impl Synom for ExprMatch { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1452 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1453 | match_: keyword!(match) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1454 | obj: expr_no_struct >> |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1455 | res: braces!(many0!(Arm::parse)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1456 | ({ |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1457 | let (arms, brace) = res; |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1458 | ExprMatch { |
| 1459 | expr: Box::new(obj), |
| 1460 | match_token: match_, |
| 1461 | brace_token: brace, |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1462 | arms: arms, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1463 | } |
| 1464 | }) |
| 1465 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1466 | } |
David Tolnay | 1978c67 | 2016-10-27 22:05:52 -0700 | [diff] [blame] | 1467 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1468 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1469 | impl Synom for ExprCatch { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1470 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1471 | do_: keyword!(do) >> |
| 1472 | catch_: keyword!(catch) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1473 | catch_block: syn!(Block) >> |
| 1474 | (ExprCatch { |
| 1475 | block: catch_block, |
| 1476 | do_token: do_, |
| 1477 | catch_token: catch_, |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 1478 | }) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1479 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1480 | } |
Arnavion | 02ef13f | 2017-04-25 00:54:31 -0700 | [diff] [blame] | 1481 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1482 | #[cfg(feature = "full")] |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 1483 | impl Synom for ExprYield { |
| 1484 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1485 | yield_: keyword!(yield) >> |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 1486 | expr: option!(syn!(Expr)) >> |
| 1487 | (ExprYield { |
| 1488 | yield_token: yield_, |
| 1489 | expr: expr.map(Box::new), |
| 1490 | }) |
| 1491 | )); |
| 1492 | } |
| 1493 | |
| 1494 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1495 | impl Synom for Arm { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1496 | named!(parse -> Self, do_parse!( |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1497 | attrs: many0!(Attribute::parse_outer) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1498 | pats: call!(Delimited::parse_separated_nonempty) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1499 | guard: option!(tuple!(keyword!(if), syn!(Expr))) >> |
| 1500 | rocket: punct!(=>) >> |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1501 | body: do_parse!( |
| 1502 | expr: alt!(expr_nosemi | syn!(Expr)) >> |
| 1503 | comma1: cond!(arm_expr_requires_comma(&expr), alt!( |
| 1504 | map!(input_end!(), |_| None) |
| 1505 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1506 | map!(punct!(,), Some) |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1507 | )) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1508 | comma2: cond!(!arm_expr_requires_comma(&expr), option!(punct!(,))) >> |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 1509 | (expr, comma1.and_then(|x| x).or_else(|| comma2.and_then(|x| x))) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1510 | ) >> |
| 1511 | (Arm { |
| 1512 | rocket_token: rocket, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1513 | if_token: guard.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1514 | attrs: attrs, |
| 1515 | pats: pats, |
| 1516 | guard: guard.map(|p| Box::new(p.1)), |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 1517 | body: Box::new(body.0), |
| 1518 | comma: body.1, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1519 | }) |
| 1520 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1521 | } |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 1522 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1523 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1524 | named!(expr_closure(allow_struct: bool) -> ExprKind, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1525 | capture: syn!(CaptureBy) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1526 | or1: punct!(|) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1527 | inputs: call!(Delimited::parse_terminated_with, fn_arg) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1528 | or2: punct!(|) >> |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1529 | ret_and_body: alt!( |
| 1530 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1531 | arrow: punct!(->) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1532 | ty: syn!(Type) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1533 | body: syn!(Block) >> |
David Tolnay | 4a3f59a | 2017-12-28 21:21:12 -0500 | [diff] [blame^] | 1534 | (ReturnType::Type(arrow, Box::new(ty)), |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1535 | ExprKind::Block(ExprBlock { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1536 | block: body, |
| 1537 | }).into()) |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1538 | ) |
| 1539 | | |
David Tolnay | f93b90d | 2017-11-11 19:21:26 -0800 | [diff] [blame] | 1540 | map!(ambiguous_expr!(allow_struct), |e| (ReturnType::Default, e)) |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1541 | ) >> |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1542 | (ExprClosure { |
| 1543 | capture: capture, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1544 | or1_token: or1, |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 1545 | inputs: inputs, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1546 | or2_token: or2, |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 1547 | output: ret_and_body.0, |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1548 | body: Box::new(ret_and_body.1), |
| 1549 | }.into()) |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1550 | )); |
| 1551 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1552 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1553 | named!(fn_arg -> FnArg, do_parse!( |
| 1554 | pat: syn!(Pat) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1555 | ty: option!(tuple!(punct!(:), syn!(Type))) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1556 | ({ |
David Tolnay | 80ed55f | 2017-12-27 22:54:40 -0500 | [diff] [blame] | 1557 | if let Some((colon, ty)) = ty { |
| 1558 | FnArg::Captured(ArgCaptured { |
| 1559 | pat: pat, |
| 1560 | colon_token: colon, |
| 1561 | ty: ty, |
| 1562 | }) |
| 1563 | } else { |
| 1564 | FnArg::Inferred(pat) |
| 1565 | } |
David Tolnay | bb6feae | 2016-10-02 21:25:20 -0700 | [diff] [blame] | 1566 | }) |
Gregory Katz | 3e562cc | 2016-09-28 18:33:02 -0400 | [diff] [blame] | 1567 | )); |
| 1568 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1569 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1570 | impl Synom for ExprWhile { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1571 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1572 | lbl: option!(tuple!(syn!(Lifetime), punct!(:))) >> |
| 1573 | while_: keyword!(while) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1574 | cond: expr_no_struct >> |
| 1575 | while_block: syn!(Block) >> |
| 1576 | (ExprWhile { |
| 1577 | while_token: while_, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1578 | colon_token: lbl.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1579 | cond: Box::new(cond), |
| 1580 | body: while_block, |
| 1581 | label: lbl.map(|p| p.0), |
| 1582 | }) |
| 1583 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1586 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1587 | impl Synom for ExprWhileLet { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1588 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1589 | lbl: option!(tuple!(syn!(Lifetime), punct!(:))) >> |
| 1590 | while_: keyword!(while) >> |
| 1591 | let_: keyword!(let) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1592 | pat: syn!(Pat) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1593 | eq: punct!(=) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1594 | value: expr_no_struct >> |
| 1595 | while_block: syn!(Block) >> |
| 1596 | (ExprWhileLet { |
| 1597 | eq_token: eq, |
| 1598 | let_token: let_, |
| 1599 | while_token: while_, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1600 | colon_token: lbl.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1601 | pat: Box::new(pat), |
| 1602 | expr: Box::new(value), |
| 1603 | body: while_block, |
| 1604 | label: lbl.map(|p| p.0), |
| 1605 | }) |
| 1606 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1609 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1610 | impl Synom for ExprContinue { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1611 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1612 | cont: keyword!(continue) >> |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 1613 | lbl: option!(syn!(Lifetime)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1614 | (ExprContinue { |
| 1615 | continue_token: cont, |
| 1616 | label: lbl, |
| 1617 | }) |
| 1618 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1619 | } |
Gregory Katz | fd6935d | 2016-09-30 22:51:25 -0400 | [diff] [blame] | 1620 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1621 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1622 | named!(expr_break(allow_struct: bool) -> ExprKind, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1623 | break_: keyword!(break) >> |
David Tolnay | 63e3dee | 2017-06-03 20:13:17 -0700 | [diff] [blame] | 1624 | lbl: option!(syn!(Lifetime)) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1625 | // We can't allow blocks after a `break` expression when we wouldn't |
| 1626 | // allow structs, as this expression is ambiguous. |
| 1627 | val: opt_ambiguous_expr!(allow_struct) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1628 | (ExprBreak { |
| 1629 | label: lbl, |
| 1630 | expr: val.map(Box::new), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1631 | break_token: break_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1632 | }.into()) |
Gregory Katz | fd6935d | 2016-09-30 22:51:25 -0400 | [diff] [blame] | 1633 | )); |
| 1634 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1635 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1636 | named!(expr_ret(allow_struct: bool) -> ExprKind, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1637 | return_: keyword!(return) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1638 | // NOTE: return is greedy and eats blocks after it even when in a |
| 1639 | // position where structs are not allowed, such as in if statement |
| 1640 | // conditions. For example: |
| 1641 | // |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 1642 | // if return { println!("A") } {} // Prints "A" |
David Tolnay | af2557e | 2016-10-24 11:52:21 -0700 | [diff] [blame] | 1643 | ret_value: option!(ambiguous_expr!(allow_struct)) >> |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1644 | (ExprRet { |
| 1645 | expr: ret_value.map(Box::new), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1646 | return_token: return_, |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1647 | }.into()) |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 1648 | )); |
| 1649 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1650 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1651 | impl Synom for ExprStruct { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1652 | named!(parse -> Self, do_parse!( |
| 1653 | path: syn!(Path) >> |
| 1654 | data: braces!(do_parse!( |
| 1655 | fields: call!(Delimited::parse_terminated) >> |
| 1656 | base: option!( |
| 1657 | cond!(fields.is_empty() || fields.trailing_delim(), |
| 1658 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1659 | dots: punct!(..) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1660 | base: syn!(Expr) >> |
| 1661 | (dots, base) |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1662 | ) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1663 | ) |
| 1664 | ) >> |
| 1665 | (fields, base) |
| 1666 | )) >> |
| 1667 | ({ |
| 1668 | let ((fields, base), brace) = data; |
| 1669 | let (dots, rest) = match base.and_then(|b| b) { |
| 1670 | Some((dots, base)) => (Some(dots), Some(base)), |
| 1671 | None => (None, None), |
| 1672 | }; |
| 1673 | ExprStruct { |
| 1674 | brace_token: brace, |
| 1675 | path: path, |
| 1676 | fields: fields, |
| 1677 | dot2_token: dots, |
| 1678 | rest: rest.map(Box::new), |
| 1679 | } |
| 1680 | }) |
| 1681 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1684 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1685 | impl Synom for FieldValue { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1686 | named!(parse -> Self, alt!( |
| 1687 | do_parse!( |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1688 | member: syn!(Member) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1689 | colon: punct!(:) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1690 | value: syn!(Expr) >> |
| 1691 | (FieldValue { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1692 | member: member, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1693 | expr: value, |
| 1694 | is_shorthand: false, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1695 | attrs: Vec::new(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1696 | colon_token: Some(colon), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1697 | }) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1698 | ) |
| 1699 | | |
David Tolnay | bc7d7d9 | 2017-06-03 20:54:05 -0700 | [diff] [blame] | 1700 | map!(syn!(Ident), |name| FieldValue { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1701 | member: Member::Named(name), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1702 | expr: ExprKind::Path(ExprPath { qself: None, path: name.into() }).into(), |
| 1703 | is_shorthand: true, |
| 1704 | attrs: Vec::new(), |
| 1705 | colon_token: None, |
| 1706 | }) |
| 1707 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1708 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 1709 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1710 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1711 | impl Synom for ExprRepeat { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1712 | named!(parse -> Self, do_parse!( |
| 1713 | data: brackets!(do_parse!( |
| 1714 | value: syn!(Expr) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1715 | semi: punct!(;) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1716 | times: syn!(Expr) >> |
| 1717 | (value, semi, times) |
| 1718 | )) >> |
| 1719 | (ExprRepeat { |
| 1720 | expr: Box::new((data.0).0), |
| 1721 | amt: Box::new((data.0).2), |
| 1722 | bracket_token: data.1, |
| 1723 | semi_token: (data.0).1, |
| 1724 | }) |
| 1725 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1726 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 1727 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1728 | #[cfg(feature = "full")] |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 1729 | impl Synom for ExprUnsafe { |
| 1730 | named!(parse -> Self, do_parse!( |
| 1731 | unsafe_: keyword!(unsafe) >> |
| 1732 | b: syn!(Block) >> |
| 1733 | (ExprUnsafe { |
| 1734 | unsafe_token: unsafe_, |
| 1735 | block: b, |
| 1736 | }) |
| 1737 | )); |
| 1738 | } |
| 1739 | |
| 1740 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1741 | impl Synom for ExprBlock { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1742 | named!(parse -> Self, do_parse!( |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1743 | b: syn!(Block) >> |
| 1744 | (ExprBlock { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1745 | block: b, |
| 1746 | }) |
| 1747 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1748 | } |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 1749 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1750 | #[cfg(feature = "full")] |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1751 | named!(expr_range(allow_struct: bool) -> ExprKind, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1752 | limits: syn!(RangeLimits) >> |
Michael Layzell | b78f3b5 | 2017-06-04 19:03:03 -0400 | [diff] [blame] | 1753 | hi: opt_ambiguous_expr!(allow_struct) >> |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 1754 | (ExprRange { from: None, to: hi.map(Box::new), limits: limits }.into()) |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 1755 | )); |
| 1756 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1757 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1758 | impl Synom for RangeLimits { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1759 | named!(parse -> Self, alt!( |
| 1760 | // Must come before Dot2 |
David Tolnay | be55d7b | 2017-12-17 23:41:20 -0800 | [diff] [blame] | 1761 | punct!(..=) => { RangeLimits::Closed } |
| 1762 | | |
| 1763 | // Must come before Dot2 |
David Tolnay | 995bff2 | 2017-12-17 23:44:43 -0800 | [diff] [blame] | 1764 | punct!(...) => { |dot3| RangeLimits::Closed(Token) } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1765 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1766 | punct!(..) => { RangeLimits::HalfOpen } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1767 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1768 | } |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 1769 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1770 | impl Synom for ExprPath { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1771 | named!(parse -> Self, do_parse!( |
| 1772 | pair: qpath >> |
| 1773 | (ExprPath { |
| 1774 | qself: pair.0, |
| 1775 | path: pair.1, |
| 1776 | }) |
| 1777 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1778 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 1779 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1780 | #[cfg(feature = "full")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 1781 | named!(and_field -> (Token![.], Member), tuple!(punct!(.), syn!(Member))); |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 1782 | |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 1783 | named!(and_index -> (Expr, token::Bracket), brackets!(syn!(Expr))); |
David Tolnay | 438c905 | 2016-10-07 23:24:48 -0700 | [diff] [blame] | 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 Block { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1787 | named!(parse -> Self, do_parse!( |
| 1788 | stmts: braces!(call!(Block::parse_within)) >> |
| 1789 | (Block { |
| 1790 | stmts: stmts.0, |
| 1791 | brace_token: stmts.1, |
| 1792 | }) |
| 1793 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1794 | } |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1795 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1796 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1797 | impl Block { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1798 | named!(pub parse_within -> Vec<Stmt>, do_parse!( |
David Tolnay | 4699a31 | 2017-12-27 14:39:22 -0500 | [diff] [blame] | 1799 | many0!(punct!(;)) >> |
| 1800 | mut standalone: many0!(terminated!(syn!(Stmt), many0!(punct!(;)))) >> |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 1801 | last: option!(do_parse!( |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1802 | attrs: many0!(Attribute::parse_outer) >> |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 1803 | mut e: syn!(Expr) >> |
| 1804 | ({ |
| 1805 | e.attrs = attrs; |
| 1806 | Stmt::Expr(Box::new(e)) |
| 1807 | }) |
| 1808 | )) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1809 | (match last { |
| 1810 | None => standalone, |
| 1811 | Some(last) => { |
Alex Crichton | 70bbd59 | 2017-08-27 10:40:03 -0700 | [diff] [blame] | 1812 | standalone.push(last); |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1813 | standalone |
| 1814 | } |
| 1815 | }) |
| 1816 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1819 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1820 | impl Synom for Stmt { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1821 | named!(parse -> Self, alt!( |
| 1822 | stmt_mac |
| 1823 | | |
| 1824 | stmt_local |
| 1825 | | |
| 1826 | stmt_item |
| 1827 | | |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1828 | stmt_blockexpr |
| 1829 | | |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1830 | stmt_expr |
| 1831 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1832 | } |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1833 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1834 | #[cfg(feature = "full")] |
David Tolnay | 13b3d35 | 2016-10-03 00:31:15 -0700 | [diff] [blame] | 1835 | named!(stmt_mac -> Stmt, do_parse!( |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1836 | attrs: many0!(Attribute::parse_outer) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1837 | what: syn!(Path) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1838 | bang: punct!(!) >> |
David Tolnay | eea28d6 | 2016-10-25 20:44:08 -0700 | [diff] [blame] | 1839 | // Only parse braces here; paren and bracket will get parsed as |
| 1840 | // expression statements |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1841 | data: braces!(syn!(TokenStream)) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1842 | semi: option!(punct!(;)) >> |
David Tolnay | 57b52bc | 2017-12-28 18:06:38 -0500 | [diff] [blame] | 1843 | (Stmt::Item(Box::new(Item::Macro(ItemMacro { |
| 1844 | attrs: attrs, |
| 1845 | ident: None, |
| 1846 | mac: Macro { |
David Tolnay | 5d55ef7 | 2016-12-21 20:20:04 -0500 | [diff] [blame] | 1847 | path: what, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1848 | bang_token: bang, |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 1849 | tokens: proc_macro2::TokenTree { |
David Tolnay | 9894256 | 2017-12-26 21:24:35 -0500 | [diff] [blame] | 1850 | span: (data.1).0, |
Alex Crichton | f9e8f1a | 2017-07-05 18:20:44 -0700 | [diff] [blame] | 1851 | kind: TokenNode::Group(Delimiter::Brace, data.0), |
David Tolnay | 369f0c5 | 2017-12-27 01:50:45 -0500 | [diff] [blame] | 1852 | }, |
David Tolnay | eea28d6 | 2016-10-25 20:44:08 -0700 | [diff] [blame] | 1853 | }, |
David Tolnay | 57b52bc | 2017-12-28 18:06:38 -0500 | [diff] [blame] | 1854 | semi_token: semi, |
| 1855 | })))) |
David Tolnay | 13b3d35 | 2016-10-03 00:31:15 -0700 | [diff] [blame] | 1856 | )); |
| 1857 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1858 | #[cfg(feature = "full")] |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 1859 | named!(stmt_local -> Stmt, do_parse!( |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1860 | attrs: many0!(Attribute::parse_outer) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1861 | let_: keyword!(let) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1862 | pat: syn!(Pat) >> |
David Tolnay | fd6bf5c | 2017-11-12 09:41:14 -0800 | [diff] [blame] | 1863 | ty: option!(tuple!(punct!(:), syn!(Type))) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1864 | init: option!(tuple!(punct!(=), syn!(Expr))) >> |
| 1865 | semi: punct!(;) >> |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 1866 | (Stmt::Local(Box::new(Local { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1867 | let_token: let_, |
| 1868 | semi_token: semi, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1869 | colon_token: ty.as_ref().map(|p| Token.0)), |
| 1870 | eq_token: init.as_ref().map(|p| Token.0)), |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 1871 | pat: Box::new(pat), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1872 | ty: ty.map(|p| Box::new(p.1)), |
| 1873 | init: init.map(|p| Box::new(p.1)), |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 1874 | attrs: attrs, |
| 1875 | }))) |
| 1876 | )); |
| 1877 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1878 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1879 | named!(stmt_item -> Stmt, map!(syn!(Item), |i| Stmt::Item(Box::new(i)))); |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 1880 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1881 | #[cfg(feature = "full")] |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1882 | named!(stmt_blockexpr -> Stmt, do_parse!( |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1883 | attrs: many0!(Attribute::parse_outer) >> |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1884 | mut e: expr_nosemi >> |
| 1885 | // If the next token is a `.` or a `?` it is special-cased to parse as |
| 1886 | // an expression instead of a blockexpression. |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1887 | not!(punct!(.)) >> |
| 1888 | not!(punct!(?)) >> |
| 1889 | semi: option!(punct!(;)) >> |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1890 | ({ |
| 1891 | e.attrs = attrs; |
| 1892 | if let Some(semi) = semi { |
| 1893 | Stmt::Semi(Box::new(e), semi) |
| 1894 | } else { |
| 1895 | Stmt::Expr(Box::new(e)) |
| 1896 | } |
| 1897 | }) |
| 1898 | )); |
David Tolnay | cfe5502 | 2016-10-02 22:02:27 -0700 | [diff] [blame] | 1899 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1900 | #[cfg(feature = "full")] |
David Tolnay | cfe5502 | 2016-10-02 22:02:27 -0700 | [diff] [blame] | 1901 | named!(stmt_expr -> Stmt, do_parse!( |
David Tolnay | 2c13645 | 2017-12-27 14:13:32 -0500 | [diff] [blame] | 1902 | attrs: many0!(Attribute::parse_outer) >> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1903 | mut e: syn!(Expr) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1904 | semi: punct!(;) >> |
David Tolnay | 7184b13 | 2016-10-30 10:06:37 -0700 | [diff] [blame] | 1905 | ({ |
| 1906 | e.attrs = attrs; |
Michael Layzell | 3541878 | 2017-06-07 09:20:25 -0400 | [diff] [blame] | 1907 | Stmt::Semi(Box::new(e), semi) |
David Tolnay | cfe5502 | 2016-10-02 22:02:27 -0700 | [diff] [blame] | 1908 | }) |
David Tolnay | 939766a | 2016-09-23 23:48:12 -0700 | [diff] [blame] | 1909 | )); |
David Tolnay | 8b07f37 | 2016-09-30 10:28:40 -0700 | [diff] [blame] | 1910 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1911 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1912 | impl Synom for Pat { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1913 | named!(parse -> Self, alt!( |
| 1914 | syn!(PatWild) => { Pat::Wild } // must be before pat_ident |
| 1915 | | |
| 1916 | syn!(PatBox) => { Pat::Box } // must be before pat_ident |
| 1917 | | |
| 1918 | syn!(PatRange) => { Pat::Range } // must be before pat_lit |
| 1919 | | |
| 1920 | syn!(PatTupleStruct) => { Pat::TupleStruct } // must be before pat_ident |
| 1921 | | |
| 1922 | syn!(PatStruct) => { Pat::Struct } // must be before pat_ident |
| 1923 | | |
David Tolnay | decf28d | 2017-11-11 11:56:45 -0800 | [diff] [blame] | 1924 | syn!(Macro) => { Pat::Macro } // must be before pat_ident |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1925 | | |
| 1926 | syn!(PatLit) => { Pat::Lit } // must be before pat_ident |
| 1927 | | |
| 1928 | syn!(PatIdent) => { Pat::Ident } // must be before pat_path |
| 1929 | | |
| 1930 | syn!(PatPath) => { Pat::Path } |
| 1931 | | |
| 1932 | syn!(PatTuple) => { Pat::Tuple } |
| 1933 | | |
| 1934 | syn!(PatRef) => { Pat::Ref } |
| 1935 | | |
| 1936 | syn!(PatSlice) => { Pat::Slice } |
| 1937 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1938 | } |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 1939 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1940 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1941 | impl Synom for PatWild { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1942 | named!(parse -> Self, map!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1943 | punct!(_), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1944 | |u| PatWild { underscore_token: u } |
| 1945 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1946 | } |
David Tolnay | 84aa075 | 2016-10-02 23:01:13 -0700 | [diff] [blame] | 1947 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1948 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1949 | impl Synom for PatBox { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1950 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1951 | boxed: keyword!(box) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1952 | pat: syn!(Pat) >> |
| 1953 | (PatBox { |
| 1954 | pat: Box::new(pat), |
| 1955 | box_token: boxed, |
| 1956 | }) |
| 1957 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1960 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1961 | impl Synom for PatIdent { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1962 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1963 | mode: option!(keyword!(ref)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1964 | mutability: syn!(Mutability) >> |
| 1965 | name: alt!( |
| 1966 | syn!(Ident) |
| 1967 | | |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1968 | keyword!(self) => { Into::into } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1969 | ) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1970 | not!(punct!(<)) >> |
| 1971 | not!(punct!(::)) >> |
| 1972 | subpat: option!(tuple!(punct!(@), syn!(Pat))) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1973 | (PatIdent { |
| 1974 | mode: match mode { |
| 1975 | Some(mode) => BindingMode::ByRef(mode, mutability), |
| 1976 | None => BindingMode::ByValue(mutability), |
| 1977 | }, |
| 1978 | ident: name, |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 1979 | at_token: subpat.as_ref().map(|p| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1980 | subpat: subpat.map(|p| Box::new(p.1)), |
| 1981 | }) |
| 1982 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1985 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1986 | impl Synom for PatTupleStruct { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1987 | named!(parse -> Self, do_parse!( |
| 1988 | path: syn!(Path) >> |
| 1989 | tuple: syn!(PatTuple) >> |
| 1990 | (PatTupleStruct { |
| 1991 | path: path, |
| 1992 | pat: tuple, |
| 1993 | }) |
| 1994 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 1997 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 1998 | impl Synom for PatStruct { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 1999 | named!(parse -> Self, do_parse!( |
| 2000 | path: syn!(Path) >> |
| 2001 | data: braces!(do_parse!( |
| 2002 | fields: call!(Delimited::parse_terminated) >> |
| 2003 | base: option!( |
| 2004 | cond!(fields.is_empty() || fields.trailing_delim(), |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2005 | punct!(..)) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2006 | ) >> |
| 2007 | (fields, base) |
| 2008 | )) >> |
| 2009 | (PatStruct { |
| 2010 | path: path, |
| 2011 | fields: (data.0).0, |
| 2012 | brace_token: data.1, |
| 2013 | dot2_token: (data.0).1.and_then(|m| m), |
| 2014 | }) |
| 2015 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2018 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2019 | impl Synom for FieldPat { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2020 | named!(parse -> Self, alt!( |
| 2021 | do_parse!( |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2022 | member: syn!(Member) >> |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2023 | colon: punct!(:) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2024 | pat: syn!(Pat) >> |
| 2025 | (FieldPat { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2026 | member: member, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2027 | pat: Box::new(pat), |
| 2028 | is_shorthand: false, |
| 2029 | attrs: Vec::new(), |
| 2030 | colon_token: Some(colon), |
| 2031 | }) |
| 2032 | ) |
| 2033 | | |
| 2034 | do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2035 | boxed: option!(keyword!(box)) >> |
| 2036 | mode: option!(keyword!(ref)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2037 | mutability: syn!(Mutability) >> |
| 2038 | ident: syn!(Ident) >> |
| 2039 | ({ |
| 2040 | let mut pat: Pat = PatIdent { |
| 2041 | mode: if let Some(mode) = mode { |
| 2042 | BindingMode::ByRef(mode, mutability) |
| 2043 | } else { |
| 2044 | BindingMode::ByValue(mutability) |
| 2045 | }, |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 2046 | ident: ident, |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2047 | subpat: None, |
| 2048 | at_token: None, |
| 2049 | }.into(); |
| 2050 | if let Some(boxed) = boxed { |
| 2051 | pat = PatBox { |
| 2052 | pat: Box::new(pat), |
| 2053 | box_token: boxed, |
| 2054 | }.into(); |
| 2055 | } |
| 2056 | FieldPat { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2057 | member: Member::Named(ident), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2058 | pat: Box::new(pat), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2059 | is_shorthand: true, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2060 | attrs: Vec::new(), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2061 | colon_token: None, |
| 2062 | } |
| 2063 | }) |
| 2064 | ) |
| 2065 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2068 | #[cfg(feature = "full")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2069 | impl Synom for Member { |
| 2070 | named!(parse -> Self, alt!( |
| 2071 | syn!(Ident) => { Member::Named } |
| 2072 | | |
| 2073 | syn!(Index) => { Member::Unnamed } |
| 2074 | )); |
| 2075 | } |
| 2076 | |
| 2077 | #[cfg(feature = "full")] |
| 2078 | impl Synom for Index { |
| 2079 | named!(parse -> Self, do_parse!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2080 | lit: syn!(Lit) >> |
| 2081 | ({ |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2082 | if let Ok(i) = lit.value.to_string().parse() { |
| 2083 | Index { index: i, span: lit.span } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2084 | } else { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2085 | return parse_error(); |
David Tolnay | da16738 | 2016-10-30 13:34:09 -0700 | [diff] [blame] | 2086 | } |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2087 | }) |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2088 | )); |
| 2089 | } |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2090 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2091 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2092 | impl Synom for PatPath { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2093 | named!(parse -> Self, map!( |
| 2094 | syn!(ExprPath), |
David Tolnay | bc7d7d9 | 2017-06-03 20:54:05 -0700 | [diff] [blame] | 2095 | |p| PatPath { qself: p.qself, path: p.path } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2096 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2097 | } |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 2098 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2099 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2100 | impl Synom for PatTuple { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2101 | named!(parse -> Self, do_parse!( |
| 2102 | data: parens!(do_parse!( |
| 2103 | elems: call!(Delimited::parse_terminated) >> |
| 2104 | dotdot: map!(cond!( |
| 2105 | elems.is_empty() || elems.trailing_delim(), |
| 2106 | option!(do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2107 | dots: punct!(..) >> |
| 2108 | trailing: option!(punct!(,)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2109 | (dots, trailing) |
| 2110 | )) |
David Tolnay | bc7d7d9 | 2017-06-03 20:54:05 -0700 | [diff] [blame] | 2111 | ), |x| x.and_then(|x| x)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2112 | rest: cond!(match dotdot { |
| 2113 | Some((_, Some(_))) => true, |
| 2114 | _ => false, |
| 2115 | }, |
| 2116 | call!(Delimited::parse_terminated)) >> |
| 2117 | (elems, dotdot, rest) |
| 2118 | )) >> |
| 2119 | ({ |
| 2120 | let ((mut elems, dotdot, rest), parens) = data; |
| 2121 | let (dotdot, trailing) = match dotdot { |
| 2122 | Some((a, b)) => (Some(a), Some(b)), |
| 2123 | None => (None, None), |
| 2124 | }; |
| 2125 | PatTuple { |
| 2126 | paren_token: parens, |
| 2127 | dots_pos: dotdot.as_ref().map(|_| elems.len()), |
| 2128 | dot2_token: dotdot, |
| 2129 | comma_token: trailing.and_then(|b| b), |
| 2130 | pats: { |
| 2131 | if let Some(rest) = rest { |
| 2132 | for elem in rest { |
| 2133 | elems.push(elem); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2134 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2135 | } |
| 2136 | elems |
| 2137 | }, |
| 2138 | } |
| 2139 | }) |
| 2140 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2141 | } |
David Tolnay | fbb7323 | 2016-10-03 01:00:06 -0700 | [diff] [blame] | 2142 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2143 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2144 | impl Synom for PatRef { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2145 | named!(parse -> Self, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2146 | and: punct!(&) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2147 | mutability: syn!(Mutability) >> |
| 2148 | pat: syn!(Pat) >> |
| 2149 | (PatRef { |
| 2150 | pat: Box::new(pat), |
| 2151 | mutbl: mutability, |
| 2152 | and_token: and, |
| 2153 | }) |
| 2154 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2155 | } |
David Tolnay | ffdb97f | 2016-10-03 01:28:33 -0700 | [diff] [blame] | 2156 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2157 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2158 | impl Synom for PatLit { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2159 | named!(parse -> Self, do_parse!( |
| 2160 | lit: pat_lit_expr >> |
| 2161 | (if let ExprKind::Path(_) = lit.node { |
| 2162 | return parse_error(); // these need to be parsed by pat_path |
| 2163 | } else { |
| 2164 | PatLit { |
| 2165 | expr: Box::new(lit), |
| 2166 | } |
| 2167 | }) |
| 2168 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2169 | } |
David Tolnay | e131090 | 2016-10-29 23:40:00 -0700 | [diff] [blame] | 2170 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2171 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2172 | impl Synom for PatRange { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2173 | named!(parse -> Self, do_parse!( |
| 2174 | lo: pat_lit_expr >> |
| 2175 | limits: syn!(RangeLimits) >> |
| 2176 | hi: pat_lit_expr >> |
| 2177 | (PatRange { |
| 2178 | lo: Box::new(lo), |
| 2179 | hi: Box::new(hi), |
| 2180 | limits: limits, |
| 2181 | }) |
| 2182 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2183 | } |
David Tolnay | e131090 | 2016-10-29 23:40:00 -0700 | [diff] [blame] | 2184 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2185 | #[cfg(feature = "full")] |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2186 | named!(pat_lit_expr -> Expr, do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2187 | neg: option!(punct!(-)) >> |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2188 | v: alt!( |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2189 | syn!(Lit) => { ExprKind::Lit } |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2190 | | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2191 | syn!(ExprPath) => { ExprKind::Path } |
David Tolnay | 2cfddc6 | 2016-10-30 01:03:27 -0700 | [diff] [blame] | 2192 | ) >> |
David Tolnay | c29b989 | 2017-12-27 22:58:14 -0500 | [diff] [blame] | 2193 | (if let Some(neg) = neg { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2194 | ExprKind::Unary(ExprUnary { |
David Tolnay | c29b989 | 2017-12-27 22:58:14 -0500 | [diff] [blame] | 2195 | op: UnOp::Neg(neg), |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2196 | expr: Box::new(v.into()) |
| 2197 | }).into() |
David Tolnay | 0ad9e9f | 2016-10-29 22:20:02 -0700 | [diff] [blame] | 2198 | } else { |
David Tolnay | 7184b13 | 2016-10-30 10:06:37 -0700 | [diff] [blame] | 2199 | v.into() |
David Tolnay | 0ad9e9f | 2016-10-29 22:20:02 -0700 | [diff] [blame] | 2200 | }) |
| 2201 | )); |
David Tolnay | 8b308c2 | 2016-10-03 01:24:10 -0700 | [diff] [blame] | 2202 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2203 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2204 | impl Synom for PatSlice { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2205 | named!(parse -> Self, map!( |
| 2206 | brackets!(do_parse!( |
| 2207 | before: call!(Delimited::parse_terminated) >> |
| 2208 | middle: option!(do_parse!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2209 | dots: punct!(..) >> |
| 2210 | trailing: option!(punct!(,)) >> |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2211 | (dots, trailing) |
| 2212 | )) >> |
| 2213 | after: cond!( |
| 2214 | match middle { |
| 2215 | Some((_, ref trailing)) => trailing.is_some(), |
| 2216 | _ => false, |
| 2217 | }, |
| 2218 | call!(Delimited::parse_terminated) |
| 2219 | ) >> |
| 2220 | (before, middle, after) |
| 2221 | )), |
| 2222 | |((before, middle, after), brackets)| { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2223 | let mut before: Delimited<Pat, Token![,]> = before; |
| 2224 | let after: Option<Delimited<Pat, Token![,]>> = after; |
| 2225 | let middle: Option<(Token![..], Option<Token![,]>)> = middle; |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2226 | PatSlice { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2227 | dot2_token: middle.as_ref().map(|m| Token.0)), |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2228 | comma_token: middle.as_ref().and_then(|m| { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2229 | m.1.as_ref().map(|m| Token) |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2230 | }), |
| 2231 | bracket_token: brackets, |
| 2232 | middle: middle.and_then(|_| { |
| 2233 | if !before.is_empty() && !before.trailing_delim() { |
| 2234 | Some(Box::new(before.pop().unwrap().into_item())) |
| 2235 | } else { |
| 2236 | None |
| 2237 | } |
| 2238 | }), |
| 2239 | front: before, |
| 2240 | back: after.unwrap_or_default(), |
David Tolnay | e1f13c3 | 2016-10-29 23:34:40 -0700 | [diff] [blame] | 2241 | } |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2242 | } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2243 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2244 | } |
David Tolnay | 435a9a8 | 2016-10-29 13:47:20 -0700 | [diff] [blame] | 2245 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2246 | #[cfg(feature = "full")] |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2247 | impl Synom for CaptureBy { |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2248 | named!(parse -> Self, alt!( |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2249 | keyword!(move) => { CaptureBy::Value } |
Michael Layzell | 92639a5 | 2017-06-01 00:07:44 -0400 | [diff] [blame] | 2250 | | |
| 2251 | epsilon!() => { |_| CaptureBy::Ref } |
| 2252 | )); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 2253 | } |
David Tolnay | b9c8e32 | 2016-09-23 20:48:37 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2256 | #[cfg(feature = "printing")] |
| 2257 | mod printing { |
| 2258 | use super::*; |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2259 | #[cfg(feature = "full")] |
David Tolnay | 13b3d35 | 2016-10-03 00:31:15 -0700 | [diff] [blame] | 2260 | use attr::FilterAttrs; |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 2261 | use quote::{ToTokens, Tokens}; |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2262 | #[cfg(feature = "full")] |
| 2263 | use proc_macro2::{TokenTree, TokenNode, Literal}; |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2264 | |
David Tolnay | bcf2602 | 2017-12-25 22:10:52 -0500 | [diff] [blame] | 2265 | // If the given expression is a bare `ExprStruct`, wraps it in parenthesis |
| 2266 | // before appending it to `Tokens`. |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2267 | #[cfg(feature = "full")] |
| 2268 | fn wrap_bare_struct(tokens: &mut Tokens, e: &Expr) { |
| 2269 | if let ExprKind::Struct(_) = e.node { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 2270 | token::Paren::default().surround(tokens, |tokens| { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2271 | e.to_tokens(tokens); |
| 2272 | }); |
| 2273 | } else { |
| 2274 | e.to_tokens(tokens); |
| 2275 | } |
| 2276 | } |
| 2277 | |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2278 | impl ToTokens for Expr { |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2279 | #[cfg(feature = "full")] |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2280 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 7184b13 | 2016-10-30 10:06:37 -0700 | [diff] [blame] | 2281 | tokens.append_all(self.attrs.outer()); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2282 | self.node.to_tokens(tokens) |
| 2283 | } |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2284 | |
| 2285 | #[cfg(not(feature = "full"))] |
| 2286 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2287 | self.node.to_tokens(tokens) |
| 2288 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2291 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2292 | impl ToTokens for ExprBox { |
| 2293 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2294 | self.box_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2295 | self.expr.to_tokens(tokens); |
| 2296 | } |
| 2297 | } |
| 2298 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2299 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2300 | impl ToTokens for ExprInPlace { |
| 2301 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 2302 | match self.kind { |
| 2303 | InPlaceKind::Arrow(ref arrow) => { |
| 2304 | self.place.to_tokens(tokens); |
| 2305 | arrow.to_tokens(tokens); |
| 2306 | self.value.to_tokens(tokens); |
| 2307 | } |
| 2308 | InPlaceKind::In(ref _in) => { |
| 2309 | _in.to_tokens(tokens); |
| 2310 | self.place.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2311 | // NOTE: The second operand must be in a block, add one if |
| 2312 | // it is not present. |
| 2313 | if let ExprKind::Block(_) = self.value.node { |
| 2314 | self.value.to_tokens(tokens); |
| 2315 | } else { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 2316 | token::Brace::default().surround(tokens, |tokens| { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2317 | self.value.to_tokens(tokens); |
| 2318 | }) |
| 2319 | } |
Michael Layzell | 6a5a164 | 2017-06-04 19:35:15 -0400 | [diff] [blame] | 2320 | } |
| 2321 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2322 | } |
| 2323 | } |
| 2324 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2325 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2326 | impl ToTokens for ExprArray { |
| 2327 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2328 | self.bracket_token.surround(tokens, |tokens| { |
| 2329 | self.exprs.to_tokens(tokens); |
| 2330 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | impl ToTokens for ExprCall { |
| 2335 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2336 | self.func.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2337 | self.paren_token.surround(tokens, |tokens| { |
| 2338 | self.args.to_tokens(tokens); |
| 2339 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2340 | } |
| 2341 | } |
| 2342 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2343 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2344 | impl ToTokens for ExprMethodCall { |
| 2345 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2346 | self.expr.to_tokens(tokens); |
| 2347 | self.dot_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2348 | self.method.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2349 | if !self.typarams.is_empty() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2350 | TokensOrDefault(&self.colon2_token).to_tokens(tokens); |
| 2351 | TokensOrDefault(&self.lt_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2352 | self.typarams.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2353 | TokensOrDefault(&self.gt_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2354 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2355 | self.paren_token.surround(tokens, |tokens| { |
| 2356 | self.args.to_tokens(tokens); |
| 2357 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2361 | #[cfg(feature = "full")] |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 2362 | impl ToTokens for ExprTuple { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2363 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2364 | self.paren_token.surround(tokens, |tokens| { |
| 2365 | self.args.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2366 | // If we only have one argument, we need a trailing comma to |
David Tolnay | 0536258 | 2017-12-26 01:33:57 -0500 | [diff] [blame] | 2367 | // distinguish ExprTuple from ExprParen. |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2368 | if self.args.len() == 1 && !self.args.trailing_delim() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2369 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2370 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2371 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | impl ToTokens for ExprBinary { |
| 2376 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2377 | self.left.to_tokens(tokens); |
| 2378 | self.op.to_tokens(tokens); |
| 2379 | self.right.to_tokens(tokens); |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | impl ToTokens for ExprUnary { |
| 2384 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2385 | self.op.to_tokens(tokens); |
| 2386 | self.expr.to_tokens(tokens); |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | impl ToTokens for ExprCast { |
| 2391 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2392 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2393 | self.as_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2394 | self.ty.to_tokens(tokens); |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | impl ToTokens for ExprType { |
| 2399 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2400 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2401 | self.colon_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2402 | self.ty.to_tokens(tokens); |
| 2403 | } |
| 2404 | } |
| 2405 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2406 | #[cfg(feature = "full")] |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 2407 | fn maybe_wrap_else( |
| 2408 | tokens: &mut Tokens, |
| 2409 | else_token: &Option<Token![else]>, |
| 2410 | if_false: &Option<Box<Expr>>, |
| 2411 | ) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2412 | if let Some(ref if_false) = *if_false { |
David Tolnay | bb4ca9f | 2017-12-26 12:28:58 -0500 | [diff] [blame] | 2413 | TokensOrDefault(else_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2414 | |
| 2415 | // If we are not one of the valid expressions to exist in an else |
| 2416 | // clause, wrap ourselves in a block. |
| 2417 | match if_false.node { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 2418 | ExprKind::If(_) | ExprKind::IfLet(_) | ExprKind::Block(_) => { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2419 | if_false.to_tokens(tokens); |
| 2420 | } |
| 2421 | _ => { |
David Tolnay | 32954ef | 2017-12-26 22:43:16 -0500 | [diff] [blame] | 2422 | token::Brace::default().surround(tokens, |tokens| { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2423 | if_false.to_tokens(tokens); |
| 2424 | }); |
| 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2431 | impl ToTokens for ExprIf { |
| 2432 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2433 | self.if_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2434 | wrap_bare_struct(tokens, &self.cond); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2435 | self.if_true.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2436 | maybe_wrap_else(tokens, &self.else_token, &self.if_false); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2437 | } |
| 2438 | } |
| 2439 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2440 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2441 | impl ToTokens for ExprIfLet { |
| 2442 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2443 | self.if_token.to_tokens(tokens); |
| 2444 | self.let_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2445 | self.pat.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2446 | self.eq_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2447 | wrap_bare_struct(tokens, &self.expr); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2448 | self.if_true.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2449 | maybe_wrap_else(tokens, &self.else_token, &self.if_false); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2450 | } |
| 2451 | } |
| 2452 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2453 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2454 | impl ToTokens for ExprWhile { |
| 2455 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2456 | if self.label.is_some() { |
| 2457 | self.label.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2458 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2459 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2460 | self.while_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2461 | wrap_bare_struct(tokens, &self.cond); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2462 | self.body.to_tokens(tokens); |
| 2463 | } |
| 2464 | } |
| 2465 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2466 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2467 | impl ToTokens for ExprWhileLet { |
| 2468 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2469 | if self.label.is_some() { |
| 2470 | self.label.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2471 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2472 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2473 | self.while_token.to_tokens(tokens); |
| 2474 | self.let_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2475 | self.pat.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2476 | self.eq_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2477 | wrap_bare_struct(tokens, &self.expr); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2478 | self.body.to_tokens(tokens); |
| 2479 | } |
| 2480 | } |
| 2481 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2482 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2483 | impl ToTokens for ExprForLoop { |
| 2484 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2485 | if self.label.is_some() { |
| 2486 | self.label.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2487 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2488 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2489 | self.for_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2490 | self.pat.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2491 | self.in_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2492 | wrap_bare_struct(tokens, &self.expr); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2493 | self.body.to_tokens(tokens); |
| 2494 | } |
| 2495 | } |
| 2496 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2497 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2498 | impl ToTokens for ExprLoop { |
| 2499 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2500 | if self.label.is_some() { |
| 2501 | self.label.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2502 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2503 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2504 | self.loop_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2505 | self.body.to_tokens(tokens); |
| 2506 | } |
| 2507 | } |
| 2508 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2509 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2510 | impl ToTokens for ExprMatch { |
| 2511 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2512 | self.match_token.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2513 | wrap_bare_struct(tokens, &self.expr); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2514 | self.brace_token.surround(tokens, |tokens| { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 2515 | for (i, arm) in self.arms.iter().enumerate() { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2516 | arm.to_tokens(tokens); |
| 2517 | // Ensure that we have a comma after a non-block arm, except |
| 2518 | // for the last one. |
| 2519 | let is_last = i == self.arms.len() - 1; |
Alex Crichton | 03b3027 | 2017-08-28 09:35:24 -0700 | [diff] [blame] | 2520 | 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] | 2521 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2522 | } |
| 2523 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2524 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2528 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2529 | impl ToTokens for ExprCatch { |
| 2530 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2531 | self.do_token.to_tokens(tokens); |
| 2532 | self.catch_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2533 | self.block.to_tokens(tokens); |
| 2534 | } |
| 2535 | } |
| 2536 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2537 | #[cfg(feature = "full")] |
Alex Crichton | fe11046 | 2017-06-01 12:49:27 -0700 | [diff] [blame] | 2538 | impl ToTokens for ExprYield { |
| 2539 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2540 | self.yield_token.to_tokens(tokens); |
| 2541 | self.expr.to_tokens(tokens); |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2546 | impl ToTokens for ExprClosure { |
| 2547 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2548 | self.capture.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2549 | self.or1_token.to_tokens(tokens); |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 2550 | for item in self.inputs.iter() { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2551 | match **item.item() { |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 2552 | FnArg::Captured(ArgCaptured { |
| 2553 | ref pat, |
| 2554 | ty: Type::Infer(_), |
| 2555 | .. |
| 2556 | }) => { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2557 | pat.to_tokens(tokens); |
David Tolnay | 9636c05 | 2016-10-02 17:11:17 -0700 | [diff] [blame] | 2558 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2559 | _ => item.item().to_tokens(tokens), |
David Tolnay | 3c2467c | 2016-10-02 17:55:08 -0700 | [diff] [blame] | 2560 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2561 | item.delimiter().to_tokens(tokens); |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2562 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2563 | self.or2_token.to_tokens(tokens); |
David Tolnay | 7f67574 | 2017-12-27 22:43:21 -0500 | [diff] [blame] | 2564 | self.output.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2565 | self.body.to_tokens(tokens); |
| 2566 | } |
| 2567 | } |
| 2568 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2569 | #[cfg(feature = "full")] |
Nika Layzell | 640832a | 2017-12-04 13:37:09 -0500 | [diff] [blame] | 2570 | impl ToTokens for ExprUnsafe { |
| 2571 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2572 | self.unsafe_token.to_tokens(tokens); |
| 2573 | self.block.to_tokens(tokens); |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2578 | impl ToTokens for ExprBlock { |
| 2579 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2580 | self.block.to_tokens(tokens); |
| 2581 | } |
| 2582 | } |
| 2583 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2584 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2585 | impl ToTokens for ExprAssign { |
| 2586 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2587 | self.left.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2588 | self.eq_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2589 | self.right.to_tokens(tokens); |
| 2590 | } |
| 2591 | } |
| 2592 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2593 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2594 | impl ToTokens for ExprAssignOp { |
| 2595 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2596 | self.left.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2597 | self.op.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2598 | self.right.to_tokens(tokens); |
| 2599 | } |
| 2600 | } |
| 2601 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2602 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2603 | impl ToTokens for ExprField { |
| 2604 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2605 | self.base.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2606 | self.dot_token.to_tokens(tokens); |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2607 | self.member.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2608 | } |
| 2609 | } |
| 2610 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2611 | #[cfg(feature = "full")] |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2612 | impl ToTokens for Member { |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2613 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2614 | match *self { |
| 2615 | Member::Named(ident) => ident.to_tokens(tokens), |
| 2616 | Member::Unnamed(ref index) => index.to_tokens(tokens), |
| 2617 | } |
| 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | #[cfg(feature = "full")] |
| 2622 | impl ToTokens for Index { |
| 2623 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2624 | tokens.append(TokenTree { |
| 2625 | span: self.span, |
David Tolnay | 9bce057 | 2017-12-27 22:24:09 -0500 | [diff] [blame] | 2626 | kind: TokenNode::Literal(Literal::integer(i64::from(self.index))), |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2627 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | impl ToTokens for ExprIndex { |
| 2632 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2633 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2634 | self.bracket_token.surround(tokens, |tokens| { |
| 2635 | self.index.to_tokens(tokens); |
| 2636 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2640 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2641 | impl ToTokens for ExprRange { |
| 2642 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2643 | self.from.to_tokens(tokens); |
David Tolnay | 475288a | 2017-12-19 22:59:44 -0800 | [diff] [blame] | 2644 | match self.limits { |
| 2645 | RangeLimits::HalfOpen(ref t) => t.to_tokens(tokens), |
| 2646 | RangeLimits::Closed(ref t) => t.to_tokens(tokens), |
| 2647 | } |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2648 | self.to.to_tokens(tokens); |
| 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | impl ToTokens for ExprPath { |
| 2653 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2654 | ::PathTokens(&self.qself, &self.path).to_tokens(tokens) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2655 | } |
| 2656 | } |
| 2657 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2658 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2659 | impl ToTokens for ExprAddrOf { |
| 2660 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2661 | self.and_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2662 | self.mutbl.to_tokens(tokens); |
| 2663 | self.expr.to_tokens(tokens); |
| 2664 | } |
| 2665 | } |
| 2666 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2667 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2668 | impl ToTokens for ExprBreak { |
| 2669 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2670 | self.break_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2671 | self.label.to_tokens(tokens); |
| 2672 | self.expr.to_tokens(tokens); |
| 2673 | } |
| 2674 | } |
| 2675 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2676 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2677 | impl ToTokens for ExprContinue { |
| 2678 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2679 | self.continue_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2680 | self.label.to_tokens(tokens); |
| 2681 | } |
| 2682 | } |
| 2683 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2684 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2685 | impl ToTokens for ExprRet { |
| 2686 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2687 | self.return_token.to_tokens(tokens); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2688 | self.expr.to_tokens(tokens); |
| 2689 | } |
| 2690 | } |
| 2691 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2692 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2693 | impl ToTokens for ExprStruct { |
| 2694 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2695 | self.path.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2696 | self.brace_token.surround(tokens, |tokens| { |
| 2697 | self.fields.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2698 | if self.rest.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2699 | TokensOrDefault(&self.dot2_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2700 | self.rest.to_tokens(tokens); |
| 2701 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2702 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2703 | } |
| 2704 | } |
| 2705 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2706 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2707 | impl ToTokens for ExprRepeat { |
| 2708 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2709 | self.bracket_token.surround(tokens, |tokens| { |
| 2710 | self.expr.to_tokens(tokens); |
| 2711 | self.semi_token.to_tokens(tokens); |
| 2712 | self.amt.to_tokens(tokens); |
| 2713 | }) |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2714 | } |
| 2715 | } |
| 2716 | |
Michael Layzell | 93c3628 | 2017-06-04 20:43:14 -0400 | [diff] [blame] | 2717 | impl ToTokens for ExprGroup { |
| 2718 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2719 | self.group_token.surround(tokens, |tokens| { |
| 2720 | self.expr.to_tokens(tokens); |
| 2721 | }); |
| 2722 | } |
| 2723 | } |
| 2724 | |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2725 | impl ToTokens for ExprParen { |
| 2726 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2727 | self.paren_token.surround(tokens, |tokens| { |
| 2728 | self.expr.to_tokens(tokens); |
| 2729 | }); |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2730 | } |
| 2731 | } |
| 2732 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2733 | #[cfg(feature = "full")] |
Alex Crichton | 62a0a59 | 2017-05-22 13:58:53 -0700 | [diff] [blame] | 2734 | impl ToTokens for ExprTry { |
| 2735 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2736 | self.expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2737 | self.question_token.to_tokens(tokens); |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2738 | } |
| 2739 | } |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2740 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2741 | #[cfg(feature = "full")] |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 2742 | impl ToTokens for FieldValue { |
| 2743 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2744 | self.member.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2745 | // XXX: Override self.is_shorthand if expr is not an IdentExpr with |
| 2746 | // the ident self.ident? |
David Tolnay | 276690f | 2016-10-30 12:06:59 -0700 | [diff] [blame] | 2747 | if !self.is_shorthand { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2748 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
David Tolnay | 276690f | 2016-10-30 12:06:59 -0700 | [diff] [blame] | 2749 | self.expr.to_tokens(tokens); |
| 2750 | } |
David Tolnay | 055a704 | 2016-10-02 19:23:54 -0700 | [diff] [blame] | 2751 | } |
| 2752 | } |
| 2753 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2754 | #[cfg(feature = "full")] |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2755 | impl ToTokens for Arm { |
| 2756 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2757 | tokens.append_all(&self.attrs); |
| 2758 | self.pats.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2759 | if self.guard.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2760 | TokensOrDefault(&self.if_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2761 | self.guard.to_tokens(tokens); |
| 2762 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2763 | self.rocket_token.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2764 | self.body.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2765 | self.comma.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2766 | } |
| 2767 | } |
| 2768 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2769 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2770 | impl ToTokens for PatWild { |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2771 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2772 | self.underscore_token.to_tokens(tokens); |
| 2773 | } |
| 2774 | } |
| 2775 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2776 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2777 | impl ToTokens for PatIdent { |
| 2778 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2779 | self.mode.to_tokens(tokens); |
| 2780 | self.ident.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2781 | if self.subpat.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2782 | TokensOrDefault(&self.at_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2783 | self.subpat.to_tokens(tokens); |
| 2784 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2785 | } |
| 2786 | } |
| 2787 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2788 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2789 | impl ToTokens for PatStruct { |
| 2790 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2791 | self.path.to_tokens(tokens); |
| 2792 | self.brace_token.surround(tokens, |tokens| { |
| 2793 | self.fields.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2794 | // NOTE: We need a comma before the dot2 token if it is present. |
| 2795 | if !self.fields.empty_or_trailing() && self.dot2_token.is_some() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2796 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2797 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2798 | self.dot2_token.to_tokens(tokens); |
| 2799 | }); |
| 2800 | } |
| 2801 | } |
| 2802 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2803 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2804 | impl ToTokens for PatTupleStruct { |
| 2805 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2806 | self.path.to_tokens(tokens); |
| 2807 | self.pat.to_tokens(tokens); |
| 2808 | } |
| 2809 | } |
| 2810 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2811 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2812 | impl ToTokens for PatPath { |
| 2813 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2814 | ::PathTokens(&self.qself, &self.path).to_tokens(tokens); |
| 2815 | } |
| 2816 | } |
| 2817 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2818 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2819 | impl ToTokens for PatTuple { |
| 2820 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2821 | self.paren_token.surround(tokens, |tokens| { |
| 2822 | for (i, token) in self.pats.iter().enumerate() { |
| 2823 | if Some(i) == self.dots_pos { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2824 | TokensOrDefault(&self.dot2_token).to_tokens(tokens); |
| 2825 | TokensOrDefault(&self.comma_token).to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2826 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2827 | token.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2828 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2829 | |
| 2830 | if Some(self.pats.len()) == self.dots_pos { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2831 | // Ensure there is a comma before the .. token. |
| 2832 | if !self.pats.empty_or_trailing() { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2833 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2834 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2835 | self.dot2_token.to_tokens(tokens); |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2836 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2837 | }); |
| 2838 | } |
| 2839 | } |
| 2840 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2841 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2842 | impl ToTokens for PatBox { |
| 2843 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2844 | self.box_token.to_tokens(tokens); |
| 2845 | self.pat.to_tokens(tokens); |
| 2846 | } |
| 2847 | } |
| 2848 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2849 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2850 | impl ToTokens for PatRef { |
| 2851 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2852 | self.and_token.to_tokens(tokens); |
| 2853 | self.mutbl.to_tokens(tokens); |
| 2854 | self.pat.to_tokens(tokens); |
| 2855 | } |
| 2856 | } |
| 2857 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2858 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2859 | impl ToTokens for PatLit { |
| 2860 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2861 | self.expr.to_tokens(tokens); |
| 2862 | } |
| 2863 | } |
| 2864 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2865 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2866 | impl ToTokens for PatRange { |
| 2867 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2868 | self.lo.to_tokens(tokens); |
David Tolnay | 475288a | 2017-12-19 22:59:44 -0800 | [diff] [blame] | 2869 | match self.limits { |
| 2870 | RangeLimits::HalfOpen(ref t) => t.to_tokens(tokens), |
| 2871 | RangeLimits::Closed(ref t) => Token.to_tokens(tokens), |
| 2872 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2873 | self.hi.to_tokens(tokens); |
| 2874 | } |
| 2875 | } |
| 2876 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2877 | #[cfg(feature = "full")] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2878 | impl ToTokens for PatSlice { |
| 2879 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2880 | // XXX: This is a mess, and it will be so easy to screw it up. How |
| 2881 | // do we make this correct itself better? |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2882 | self.bracket_token.surround(tokens, |tokens| { |
| 2883 | self.front.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2884 | |
| 2885 | // If we need a comma before the middle or standalone .. token, |
| 2886 | // then make sure it's present. |
David Tolnay | 5138205 | 2017-12-27 13:46:21 -0500 | [diff] [blame] | 2887 | if !self.front.empty_or_trailing() |
| 2888 | && (self.middle.is_some() || self.dot2_token.is_some()) |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2889 | { |
David Tolnay | f8db7ba | 2017-11-11 22:52:16 -0800 | [diff] [blame] | 2890 | <Token![,]>::default().to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | // If we have an identifier, we always need a .. token. |
| 2894 | if self.middle.is_some() { |
| 2895 | self.middle.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2896 | TokensOrDefault(&self.dot2_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2897 | } else if self.dot2_token.is_some() { |
| 2898 | self.dot2_token.to_tokens(tokens); |
| 2899 | } |
| 2900 | |
| 2901 | // Make sure we have a comma before the back half. |
| 2902 | if !self.back.is_empty() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2903 | TokensOrDefault(&self.comma_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2904 | self.back.to_tokens(tokens); |
| 2905 | } else { |
| 2906 | self.comma_token.to_tokens(tokens); |
| 2907 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2908 | }) |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2909 | } |
| 2910 | } |
| 2911 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2912 | #[cfg(feature = "full")] |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2913 | impl ToTokens for FieldPat { |
| 2914 | fn to_tokens(&self, tokens: &mut Tokens) { |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2915 | // XXX: Override is_shorthand if it was wrong? |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2916 | if !self.is_shorthand { |
David Tolnay | 85b69a4 | 2017-12-27 20:43:10 -0500 | [diff] [blame] | 2917 | self.member.to_tokens(tokens); |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2918 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
David Tolnay | 8d9e81a | 2016-10-03 22:36:32 -0700 | [diff] [blame] | 2919 | } |
| 2920 | self.pat.to_tokens(tokens); |
| 2921 | } |
| 2922 | } |
| 2923 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2924 | #[cfg(feature = "full")] |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2925 | impl ToTokens for BindingMode { |
| 2926 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2927 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2928 | BindingMode::ByRef(ref t, ref m) => { |
| 2929 | t.to_tokens(tokens); |
| 2930 | m.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2931 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2932 | BindingMode::ByValue(ref m) => { |
| 2933 | m.to_tokens(tokens); |
David Tolnay | b4ad3b5 | 2016-10-01 21:58:13 -0700 | [diff] [blame] | 2934 | } |
| 2935 | } |
| 2936 | } |
| 2937 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2938 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2939 | #[cfg(feature = "full")] |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 2940 | impl ToTokens for CaptureBy { |
| 2941 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2942 | match *self { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2943 | CaptureBy::Value(ref t) => t.to_tokens(tokens), |
David Tolnay | daaf774 | 2016-10-03 11:11:43 -0700 | [diff] [blame] | 2944 | CaptureBy::Ref => { |
| 2945 | // nothing |
| 2946 | } |
David Tolnay | 89e0567 | 2016-10-02 14:39:42 -0700 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | } |
| 2950 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2951 | #[cfg(feature = "full")] |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2952 | impl ToTokens for Block { |
| 2953 | fn to_tokens(&self, tokens: &mut Tokens) { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2954 | self.brace_token.surround(tokens, |tokens| { |
| 2955 | tokens.append_all(&self.stmts); |
| 2956 | }); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2960 | #[cfg(feature = "full")] |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2961 | impl ToTokens for Stmt { |
| 2962 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 2963 | match *self { |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2964 | Stmt::Local(ref local) => local.to_tokens(tokens), |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2965 | Stmt::Item(ref item) => item.to_tokens(tokens), |
| 2966 | Stmt::Expr(ref expr) => expr.to_tokens(tokens), |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2967 | Stmt::Semi(ref expr, ref semi) => { |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2968 | expr.to_tokens(tokens); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2969 | semi.to_tokens(tokens); |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2970 | } |
David Tolnay | 4260229 | 2016-10-01 22:25:45 -0700 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | } |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2974 | |
Michael Layzell | 734adb4 | 2017-06-07 16:58:31 -0400 | [diff] [blame] | 2975 | #[cfg(feature = "full")] |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2976 | impl ToTokens for Local { |
| 2977 | fn to_tokens(&self, tokens: &mut Tokens) { |
David Tolnay | 4e3158d | 2016-10-30 00:30:01 -0700 | [diff] [blame] | 2978 | tokens.append_all(self.attrs.outer()); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2979 | self.let_token.to_tokens(tokens); |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2980 | self.pat.to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2981 | if self.ty.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2982 | TokensOrDefault(&self.colon_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2983 | self.ty.to_tokens(tokens); |
| 2984 | } |
| 2985 | if self.init.is_some() { |
Alex Crichton | 259ee53 | 2017-07-14 06:51:02 -0700 | [diff] [blame] | 2986 | TokensOrDefault(&self.eq_token).to_tokens(tokens); |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 2987 | self.init.to_tokens(tokens); |
| 2988 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 2989 | self.semi_token.to_tokens(tokens); |
David Tolnay | 191e058 | 2016-10-02 18:31:09 -0700 | [diff] [blame] | 2990 | } |
| 2991 | } |
David Tolnay | f4bbbd9 | 2016-09-23 14:41:55 -0700 | [diff] [blame] | 2992 | } |