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

/// An else branch of an if expression.
#[derive(Debug, Clone)]
pub struct ExprElse {
    /// The `else` token.
    pub else_: Else,
    /// The body of the else statement.
    pub block: Box<ExprBlock>,
}

impl ExprElse {
    /// Access the span for the expression.
    pub fn span(&self) -> Span {
        self.else_.span().join(self.block.span())
    }
}

impl Parse for ExprElse {
    fn parse(parser: &mut Parser) -> Result<Self, ParseError> {
        Ok(ExprElse {
            else_: parser.parse()?,
            block: Box::new(parser.parse()?),
        })
    }
}