syn_solidity/expr/
tuple.rs

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