Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 1 | use std::iter::FromIterator; |
| 2 | use std::slice; |
| 3 | use std::vec; |
| 4 | |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 5 | #[cfg_attr(feature = "extra-traits", derive(Eq, PartialEq, Hash, Debug))] |
| 6 | #[cfg_attr(feature = "clone-impls", derive(Clone))] |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 7 | pub struct Delimited<T, D> { |
| 8 | inner: Vec<(T, Option<D>)> |
| 9 | } |
| 10 | |
| 11 | impl<T, D> Delimited<T, D> { |
| 12 | pub fn new() -> Delimited<T, D> { |
| 13 | Delimited { |
| 14 | inner: Vec::new(), |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | pub fn is_empty(&self) -> bool { |
| 19 | self.inner.len() == 0 |
| 20 | } |
| 21 | |
| 22 | pub fn len(&self) -> usize { |
| 23 | self.inner.len() |
| 24 | } |
| 25 | |
| 26 | pub fn get(&self, idx: usize) -> Element<&T, &D> { |
| 27 | let (ref t, ref d) = self.inner[idx]; |
| 28 | match *d { |
| 29 | Some(ref d) => Element::Delimited(t, d), |
| 30 | None => Element::End(t), |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | pub fn get_mut(&mut self, idx: usize) -> Element<&mut T, &mut D> { |
| 35 | let (ref mut t, ref mut d) = self.inner[idx]; |
| 36 | match *d { |
| 37 | Some(ref mut d) => Element::Delimited(t, d), |
| 38 | None => Element::End(t), |
| 39 | } |
| 40 | } |
| 41 | |
Alex Crichton | 0aa50e0 | 2017-07-07 20:59:03 -0700 | [diff] [blame] | 42 | pub fn first(&self) -> Option<Element<&T, &D>> { |
| 43 | self.inner.first().map(|&(ref t, ref d)| { |
| 44 | match *d { |
| 45 | Some(ref d) => Element::Delimited(t, d), |
| 46 | None => Element::End(t), |
| 47 | } |
| 48 | }) |
| 49 | } |
| 50 | |
| 51 | pub fn first_mut(&mut self) -> Option<Element<&mut T, &mut D>> { |
| 52 | self.inner.first_mut().map(|&mut (ref mut t, ref mut d)| { |
| 53 | match *d { |
| 54 | Some(ref mut d) => Element::Delimited(t, d), |
| 55 | None => Element::End(t), |
| 56 | } |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | pub fn last(&self) -> Option<Element<&T, &D>> { |
| 61 | self.inner.last().map(|&(ref t, ref d)| { |
| 62 | match *d { |
| 63 | Some(ref d) => Element::Delimited(t, d), |
| 64 | None => Element::End(t), |
| 65 | } |
| 66 | }) |
| 67 | } |
| 68 | |
| 69 | pub fn last_mut(&mut self) -> Option<Element<&mut T, &mut D>> { |
| 70 | self.inner.last_mut().map(|&mut (ref mut t, ref mut d)| { |
| 71 | match *d { |
| 72 | Some(ref mut d) => Element::Delimited(t, d), |
| 73 | None => Element::End(t), |
| 74 | } |
| 75 | }) |
| 76 | } |
| 77 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 78 | pub fn iter(&self) -> Iter<T, D> { |
| 79 | Iter { inner: self.inner.iter() } |
| 80 | } |
| 81 | |
Alex Crichton | 164c533 | 2017-07-06 13:18:34 -0700 | [diff] [blame] | 82 | pub fn iter_mut(&mut self) -> IterMut<T, D> { |
| 83 | IterMut { inner: self.inner.iter_mut() } |
| 84 | } |
| 85 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 86 | pub fn items(&self) -> Items<T, D> { |
| 87 | Items { inner: self.inner.iter() } |
| 88 | } |
| 89 | |
| 90 | pub fn push(&mut self, token: Element<T, D>) { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 91 | assert!(self.is_empty() || self.trailing_delim()); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 92 | match token { |
| 93 | Element::Delimited(t, d) => self.inner.push((t, Some(d))), |
| 94 | Element::End(t) => self.inner.push((t, None)), |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | pub fn push_first(&mut self, token: T) { |
| 99 | assert!(self.is_empty()); |
| 100 | self.inner.push((token, None)); |
| 101 | } |
| 102 | |
| 103 | pub fn push_next(&mut self, token: T, delimiter: D) { |
| 104 | self.push_trailing(delimiter); |
| 105 | self.inner.push((token, None)); |
| 106 | } |
| 107 | |
| 108 | pub fn push_trailing(&mut self, delimiter: D) { |
| 109 | let len = self.len(); |
| 110 | assert!(self.inner[len - 1].1.is_none()); |
| 111 | self.inner[len - 1].1 = Some(delimiter); |
| 112 | } |
| 113 | |
| 114 | pub fn push_default(&mut self, token: T) where D: Default { |
Alex Crichton | 337cd46 | 2017-07-06 14:47:25 -0700 | [diff] [blame] | 115 | if self.is_empty() || self.trailing_delim() { |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 116 | self.inner.push((token, None)); |
| 117 | } else { |
| 118 | self.push_next(token, D::default()); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | pub fn pop(&mut self) -> Option<Element<T, D>> { |
| 123 | self.inner.pop().map(|e| { |
| 124 | match e { |
| 125 | (t, Some(d)) => Element::Delimited(t, d), |
| 126 | (t, None) => Element::End(t), |
| 127 | } |
| 128 | }) |
| 129 | } |
| 130 | |
| 131 | pub fn into_vec(self) -> Vec<T> { |
| 132 | self.inner.into_iter().map(|t| t.0).collect() |
| 133 | } |
| 134 | |
| 135 | pub fn trailing_delim(&self) -> bool { |
| 136 | self.inner[self.inner.len() - 1].1.is_some() |
| 137 | } |
Michael Layzell | 3936ceb | 2017-07-08 00:28:36 -0400 | [diff] [blame] | 138 | |
| 139 | /// Returns true if either this `Delimited` is empty, or it has a trailing |
| 140 | /// delimiter. This is useful within `ToTokens` implementations for `syn`. |
| 141 | #[doc(hidden)] |
| 142 | pub fn empty_or_trailing(&self) -> bool { |
| 143 | self.is_empty() || self.trailing_delim() |
| 144 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | impl<T, D> From<Vec<(T, Option<D>)>> for Delimited<T, D> { |
| 148 | fn from(v: Vec<(T, Option<D>)>) -> Self { |
| 149 | Delimited { |
| 150 | inner: v, |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | impl<T, D> From<Vec<T>> for Delimited<T, D> |
| 156 | where D: Default, |
| 157 | { |
| 158 | fn from(v: Vec<T>) -> Self { |
Alex Crichton | afb49d2 | 2017-07-06 14:47:37 -0700 | [diff] [blame] | 159 | let len = v.len(); |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 160 | Delimited { |
| 161 | inner: v.into_iter().enumerate().map(|(i, item)| { |
Alex Crichton | afb49d2 | 2017-07-06 14:47:37 -0700 | [diff] [blame] | 162 | (item, if i + 1 == len {None} else {Some(D::default())}) |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 163 | }).collect(), |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | impl<T, D> FromIterator<Element<T, D>> for Delimited<T, D> { |
| 169 | fn from_iter<I: IntoIterator<Item = Element<T, D>>>(i: I) -> Self { |
| 170 | let mut ret = Delimited::new(); |
Alex Crichton | 24f1282 | 2017-07-14 07:15:32 -0700 | [diff] [blame] | 171 | ret.extend(i); |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 172 | ret |
| 173 | } |
| 174 | } |
| 175 | |
Alex Crichton | d3743d1 | 2017-07-07 20:55:24 -0700 | [diff] [blame] | 176 | impl<T, D> FromIterator<T> for Delimited<T, D> |
| 177 | where D: Default, |
| 178 | { |
| 179 | fn from_iter<I: IntoIterator<Item = T>>(i: I) -> Self { |
| 180 | let mut ret = Delimited::new(); |
Alex Crichton | 24f1282 | 2017-07-14 07:15:32 -0700 | [diff] [blame] | 181 | ret.extend(i); |
Alex Crichton | d3743d1 | 2017-07-07 20:55:24 -0700 | [diff] [blame] | 182 | ret |
| 183 | } |
| 184 | } |
| 185 | |
Alex Crichton | 24f1282 | 2017-07-14 07:15:32 -0700 | [diff] [blame] | 186 | impl<T, D> Extend<Element<T, D>> for Delimited<T, D> { |
| 187 | fn extend<I: IntoIterator<Item = Element<T, D>>>(&mut self, i: I) { |
| 188 | for element in i { |
| 189 | match element { |
| 190 | Element::Delimited(a, b) => self.inner.push((a, Some(b))), |
| 191 | Element::End(a) => self.inner.push((a, None)), |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | impl<T, D> Extend<T> for Delimited<T, D> |
| 198 | where D: Default, |
| 199 | { |
| 200 | fn extend<I: IntoIterator<Item = T>>(&mut self, i: I) { |
| 201 | for element in i { |
| 202 | self.push_default(element); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 207 | impl<'a, T, D> IntoIterator for &'a Delimited<T, D> { |
| 208 | type Item = Element<&'a T, &'a D>; |
| 209 | type IntoIter = Iter<'a, T, D>; |
| 210 | |
| 211 | fn into_iter(self) -> Iter<'a, T, D> { |
| 212 | <Delimited<T, D>>::iter(self) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | impl<T, D> IntoIterator for Delimited<T, D> { |
| 217 | type Item = Element<T, D>; |
| 218 | type IntoIter = IntoIter<T, D>; |
| 219 | |
| 220 | fn into_iter(self) -> IntoIter<T, D> { |
| 221 | IntoIter { inner: self.inner.into_iter() } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | impl<T, D> Default for Delimited<T, D> { |
| 226 | fn default() -> Self { |
| 227 | Delimited::new() |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | pub struct Iter<'a, T: 'a, D: 'a> { |
| 232 | inner: slice::Iter<'a, (T, Option<D>)>, |
| 233 | } |
| 234 | |
| 235 | impl<'a, T, D> Iterator for Iter<'a, T, D> { |
| 236 | type Item = Element<&'a T, &'a D>; |
| 237 | |
| 238 | fn next(&mut self) -> Option<Element<&'a T, &'a D>> { |
| 239 | self.inner.next().map(|pair| { |
| 240 | match pair.1 { |
| 241 | Some(ref delimited) => Element::Delimited(&pair.0, delimited), |
| 242 | None => Element::End(&pair.0), |
| 243 | } |
| 244 | }) |
| 245 | } |
| 246 | } |
| 247 | |
Alex Crichton | 164c533 | 2017-07-06 13:18:34 -0700 | [diff] [blame] | 248 | pub struct IterMut<'a, T: 'a, D: 'a> { |
| 249 | inner: slice::IterMut<'a, (T, Option<D>)>, |
| 250 | } |
| 251 | |
| 252 | impl<'a, T, D> Iterator for IterMut<'a, T, D> { |
| 253 | type Item = Element<&'a mut T, &'a mut D>; |
| 254 | |
| 255 | fn next(&mut self) -> Option<Element<&'a mut T, &'a mut D>> { |
| 256 | self.inner.next().map(|pair| { |
| 257 | match pair.1 { |
| 258 | Some(ref mut delimited) => Element::Delimited(&mut pair.0, delimited), |
| 259 | None => Element::End(&mut pair.0), |
| 260 | } |
| 261 | }) |
| 262 | } |
| 263 | } |
| 264 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 265 | pub struct Items<'a, T: 'a, D: 'a> { |
| 266 | inner: slice::Iter<'a, (T, Option<D>)>, |
| 267 | } |
| 268 | |
| 269 | impl<'a, T, D> Iterator for Items<'a, T, D> { |
| 270 | type Item = &'a T; |
| 271 | |
| 272 | fn next(&mut self) -> Option<&'a T> { |
| 273 | self.inner.next().map(|pair| &pair.0) |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | pub struct IntoIter<T, D> { |
| 278 | inner: vec::IntoIter<(T, Option<D>)>, |
| 279 | } |
| 280 | |
| 281 | impl<T, D> Iterator for IntoIter<T, D> { |
| 282 | type Item = Element<T, D>; |
| 283 | |
| 284 | fn next(&mut self) -> Option<Element<T, D>> { |
| 285 | self.inner.next().map(|pair| { |
| 286 | match pair.1 { |
| 287 | Some(v) => Element::Delimited(pair.0, v), |
| 288 | None => Element::End(pair.0) |
| 289 | } |
| 290 | }) |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | pub enum Element<T, D> { |
| 295 | Delimited(T, D), |
| 296 | End(T), |
| 297 | } |
| 298 | |
| 299 | impl<T, D> Element<T, D> { |
| 300 | pub fn into_item(self) -> T { |
| 301 | match self { |
| 302 | Element::Delimited(t, _) | |
| 303 | Element::End(t) => t, |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | pub fn item(&self) -> &T { |
| 308 | match *self { |
| 309 | Element::Delimited(ref t, _) | |
| 310 | Element::End(ref t) => t, |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | pub fn item_mut(&mut self) -> &mut T { |
| 315 | match *self { |
| 316 | Element::Delimited(ref mut t, _) | |
| 317 | Element::End(ref mut t) => t, |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | pub fn delimiter(&self) -> Option<&D> { |
| 322 | match *self { |
| 323 | Element::Delimited(_, ref d) => Some(d), |
| 324 | Element::End(_) => None, |
| 325 | } |
| 326 | } |
Nika Layzell | cda7ebd | 2017-10-24 23:10:44 -0400 | [diff] [blame] | 327 | |
| 328 | pub fn into_tuple(self) -> (T, Option<D>) { |
| 329 | match self { |
| 330 | Element::Delimited(t, d) => (t, Some(d)), |
| 331 | Element::End(t) => (t, None), |
| 332 | } |
| 333 | } |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 336 | #[cfg(feature = "parsing")] |
| 337 | mod parsing { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 338 | use super::Delimited; |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 339 | use {PResult, Cursor, Synom, parse_error}; |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 340 | |
| 341 | impl<T, D> Delimited<T, D> |
| 342 | where T: Synom, |
| 343 | D: Synom, |
| 344 | { |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 345 | pub fn parse_separated(input: Cursor) -> PResult<Self> |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 346 | { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 347 | Self::parse(input, T::parse, false) |
| 348 | } |
| 349 | |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 350 | pub fn parse_separated_nonempty(input: Cursor) -> PResult<Self> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 351 | { |
| 352 | Self::parse_separated_nonempty_with(input, T::parse) |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 355 | pub fn parse_terminated(input: Cursor) -> PResult<Self> |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 356 | { |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 357 | Self::parse_terminated_with(input, T::parse) |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | impl<T, D> Delimited<T, D> |
| 362 | where D: Synom, |
| 363 | { |
| 364 | pub fn parse_separated_nonempty_with( |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 365 | input: Cursor, |
| 366 | parse: fn(Cursor) -> PResult<T>) |
| 367 | -> PResult<Self> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 368 | { |
| 369 | match Self::parse(input, parse, false) { |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 370 | Ok((_, ref b)) if b.is_empty() => parse_error(), |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 371 | other => other, |
| 372 | } |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 375 | pub fn parse_terminated_with( |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 376 | input: Cursor, |
| 377 | parse: fn(Cursor) -> PResult<T>) |
| 378 | -> PResult<Self> |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 379 | { |
| 380 | Self::parse(input, parse, true) |
| 381 | } |
| 382 | |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 383 | fn parse(mut input: Cursor, |
| 384 | parse: fn(Cursor) -> PResult<T>, |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 385 | terminated: bool) |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 386 | -> PResult<Self> |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 387 | { |
| 388 | let mut res = Delimited::new(); |
| 389 | |
| 390 | // get the first element |
Alex Crichton | 954046c | 2017-05-30 21:49:42 -0700 | [diff] [blame] | 391 | match parse(input) { |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 392 | Err(_) => Ok((input, res)), |
| 393 | Ok((i, o)) => { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 394 | if i == input { |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 395 | return parse_error(); |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 396 | } |
| 397 | input = i; |
| 398 | res.push_first(o); |
| 399 | |
| 400 | // get the separator first |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 401 | while let Ok((i2, s)) = D::parse(input) { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 402 | if i2 == input { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | |
| 406 | // get the element next |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 407 | if let Ok((i3, o3)) = parse(i2) { |
Michael Layzell | 0a1a663 | 2017-06-02 18:07:43 -0400 | [diff] [blame] | 408 | if i3 == i2 { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 409 | break; |
| 410 | } |
| 411 | res.push_next(o3, s); |
| 412 | input = i3; |
| 413 | } else { |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | if terminated { |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 418 | if let Ok((after, sep)) = D::parse(input) { |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 419 | res.push_trailing(sep); |
| 420 | input = after; |
| 421 | } |
| 422 | } |
Michael Layzell | 760fd66 | 2017-05-31 22:46:05 -0400 | [diff] [blame] | 423 | Ok((input, res)) |
Alex Crichton | 7b9e02f | 2017-05-30 15:54:33 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
Alex Crichton | ccbb45d | 2017-05-23 10:58:24 -0700 | [diff] [blame] | 430 | #[cfg(feature = "printing")] |
| 431 | mod printing { |
| 432 | use super::*; |
| 433 | use quote::{Tokens, ToTokens}; |
| 434 | |
| 435 | |
| 436 | impl<T, D> ToTokens for Delimited<T, D> |
| 437 | where T: ToTokens, |
| 438 | D: ToTokens, |
| 439 | { |
| 440 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 441 | tokens.append_all(self.iter()) |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | impl<T, D> ToTokens for Element<T, D> |
| 446 | where T: ToTokens, |
| 447 | D: ToTokens, |
| 448 | { |
| 449 | fn to_tokens(&self, tokens: &mut Tokens) { |
| 450 | match *self { |
| 451 | Element::Delimited(ref a, ref b) => { |
| 452 | a.to_tokens(tokens); |
| 453 | b.to_tokens(tokens); |
| 454 | } |
| 455 | Element::End(ref a) => a.to_tokens(tokens), |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |