syn_solidity/stmt/
do_while.rs1use crate::{Expr, Spanned, Stmt};
2use proc_macro2::Span;
3use std::fmt;
4use syn::{
5 parse::{Parse, ParseStream},
6 token::Paren,
7 Result, Token,
8};
9
10#[derive(Clone)]
15pub struct StmtDoWhile {
16 pub do_token: Token![do],
17 pub body: Box<Stmt>,
18 pub while_token: Token![while],
19 pub paren_token: Paren,
20 pub cond: Expr,
21 pub semi_token: Token![;],
22}
23
24impl fmt::Debug for StmtDoWhile {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 f.debug_struct("DoWhile").field("body", &self.body).field("condition", &self.cond).finish()
27 }
28}
29
30impl Parse for StmtDoWhile {
31 fn parse(input: ParseStream<'_>) -> Result<Self> {
32 let content;
33 Ok(Self {
34 do_token: input.parse()?,
35 body: input.parse()?,
36 while_token: input.parse()?,
37 paren_token: syn::parenthesized!(content in input),
38 cond: content.parse()?,
39 semi_token: input.parse()?,
40 })
41 }
42}
43
44impl Spanned for StmtDoWhile {
45 fn span(&self) -> Span {
46 let span = self.do_token.span;
47 span.join(self.semi_token.span).unwrap_or(span)
48 }
49
50 fn set_span(&mut self, span: Span) {
51 self.do_token.span = span;
52 self.semi_token.span = span;
53 }
54}