syn_solidity/expr/
type.rs1use crate::{Spanned, Type, kw};
2use proc_macro2::Span;
3use std::fmt;
4use syn::{
5 Result, Token, parenthesized,
6 parse::{Parse, ParseStream},
7 token::Paren,
8};
9
10#[derive(Clone)]
12pub struct ExprTypeCall {
13 pub type_token: Token![type],
14 pub paren_token: Paren,
15 pub ty: Type,
16}
17
18impl fmt::Debug for ExprTypeCall {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 f.debug_struct("ExprTypeCall").field("ty", &self.ty).finish()
21 }
22}
23
24impl Parse for ExprTypeCall {
25 fn parse(input: ParseStream<'_>) -> Result<Self> {
26 let content;
27 Ok(Self {
28 type_token: input.parse()?,
29 paren_token: parenthesized!(content in input),
30 ty: content.parse()?,
31 })
32 }
33}
34
35impl Spanned for ExprTypeCall {
36 fn span(&self) -> Span {
37 let span = self.type_token.span;
38 span.join(self.paren_token.span.join()).unwrap_or(span)
39 }
40
41 fn set_span(&mut self, span: Span) {
42 self.type_token.span = span;
43 self.paren_token = Paren(span);
44 }
45}
46
47#[derive(Clone)]
51pub struct ExprNew {
52 pub new_token: kw::new,
53 pub ty: Type,
54}
55
56impl fmt::Debug for ExprNew {
57 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58 f.debug_struct("ExprNew").field("ty", &self.ty).finish()
59 }
60}
61
62impl Parse for ExprNew {
63 fn parse(input: ParseStream<'_>) -> Result<Self> {
64 Ok(Self { new_token: input.parse()?, ty: input.parse()? })
65 }
66}
67
68impl Spanned for ExprNew {
69 fn span(&self) -> Span {
70 let span = self.new_token.span;
71 span.join(self.ty.span()).unwrap_or(span)
72 }
73
74 fn set_span(&mut self, span: Span) {
75 self.new_token.span = span;
76 self.ty.set_span(span);
77 }
78}