syn_solidity/stmt/
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)]
14pub struct StmtWhile {
15 pub while_token: Token![while],
16 pub paren_token: Paren,
17 pub cond: Expr,
18 pub body: Box<Stmt>,
19}
20
21impl fmt::Debug for StmtWhile {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 f.debug_struct("StmtWhile").field("cond", &self.cond).field("body", &self.body).finish()
24 }
25}
26
27impl Parse for StmtWhile {
28 fn parse(input: ParseStream<'_>) -> Result<Self> {
29 let content;
30 Ok(Self {
31 while_token: input.parse()?,
32 paren_token: syn::parenthesized!(content in input),
33 cond: content.parse()?,
34 body: input.parse()?,
35 })
36 }
37}
38
39impl Spanned for StmtWhile {
40 fn span(&self) -> Span {
41 let span = self.while_token.span;
42 span.join(self.body.span()).unwrap_or(span)
43 }
44
45 fn set_span(&mut self, span: Span) {
46 self.while_token.span = span;
47 self.body.set_span(span);
48 }
49}