syn_solidity/expr/
member.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{utils::ParseNested, Expr, Spanned};
use proc_macro2::Span;
use std::fmt;
use syn::{
    parse::{Parse, ParseStream},
    Result, Token,
};

/// Access of a named member: `obj.k`.
#[derive(Clone)]
pub struct ExprMember {
    pub expr: Box<Expr>,
    pub dot_token: Token![.],
    pub member: Box<Expr>,
}

impl fmt::Debug for ExprMember {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("ExprMember")
            .field("expr", &self.expr)
            .field("member", &self.member)
            .finish()
    }
}

impl ParseNested for ExprMember {
    fn parse_nested(expr: Box<Expr>, input: ParseStream<'_>) -> Result<Self> {
        Ok(Self { expr, dot_token: input.parse()?, member: input.parse()? })
    }
}

derive_parse!(ExprMember);

impl Spanned for ExprMember {
    fn span(&self) -> Span {
        self.expr.span().join(self.member.span()).unwrap_or_else(|| {
            self.dot_token.span.join(self.member.span()).unwrap_or_else(|| self.expr.span())
        })
    }

    fn set_span(&mut self, span: Span) {
        self.expr.set_span(span);
    }
}