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
use crate::ast::{Await, Dot, Expr};
use crate::error::{ParseError, Result};
use crate::parser::Parser;
use crate::traits::Parse;
use runestick::unit::Span;

/// A return statement `<expr>.await`.
#[derive(Debug, Clone)]
pub struct ExprAwait {
    /// The expression being awaited.
    pub expr: Box<Expr>,
    /// The dot separating the expression.
    pub dot: Dot,
    /// The await token.
    pub await_: Await,
}

impl ExprAwait {
    /// Access the span of the expression.
    pub fn span(&self) -> Span {
        self.expr.span().join(self.await_.span())
    }
}

impl Parse for ExprAwait {
    fn parse(parser: &mut Parser<'_>) -> Result<Self, ParseError> {
        Ok(Self {
            expr: Box::new(parser.parse()?),
            dot: parser.parse()?,
            await_: parser.parse()?,
        })
    }
}