syn_solidity/expr/
tuple.rs

1use crate::{utils::DebugPunctuated, Expr, Spanned};
2use proc_macro2::Span;
3use std::fmt;
4use syn::{
5    parenthesized,
6    parse::{Parse, ParseStream},
7    punctuated::Punctuated,
8    token::Paren,
9    Result, Token,
10};
11
12/// A tuple expression: `(a, b, c, d)`.
13#[derive(Clone)]
14pub struct ExprTuple {
15    pub paren_token: Paren,
16    pub elems: Punctuated<Expr, Token![,]>,
17}
18
19impl fmt::Debug for ExprTuple {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        f.debug_struct("ExprTuple").field("elems", DebugPunctuated::new(&self.elems)).finish()
22    }
23}
24
25impl Parse for ExprTuple {
26    fn parse(input: ParseStream<'_>) -> Result<Self> {
27        let content;
28        Ok(Self {
29            paren_token: parenthesized!(content in input),
30            elems: content.parse_terminated(Expr::parse, Token![,])?,
31        })
32    }
33}
34
35impl Spanned for ExprTuple {
36    fn span(&self) -> Span {
37        self.paren_token.span.join()
38    }
39
40    fn set_span(&mut self, span: Span) {
41        self.paren_token = Paren(span);
42    }
43}