mago_type_syntax/ast/
conditional.rs1use serde::Serialize;
2
3use mago_span::HasSpan;
4use mago_span::Span;
5
6use crate::ast::Type;
7use crate::ast::keyword::Keyword;
8
9#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord)]
10#[repr(C)]
11pub struct ConditionalType<'input> {
12 pub subject: Box<Type<'input>>,
13 pub is: Keyword<'input>,
14 pub not: Option<Keyword<'input>>,
15 pub target: Box<Type<'input>>,
16 pub question_mark: Span,
17 pub then: Box<Type<'input>>,
18 pub colon: Span,
19 pub otherwise: Box<Type<'input>>,
20}
21
22impl ConditionalType<'_> {
23 pub fn is_negated(&self) -> bool {
24 self.not.is_some()
25 }
26}
27
28impl HasSpan for ConditionalType<'_> {
29 fn span(&self) -> Span {
30 self.subject.span().join(self.otherwise.span())
31 }
32}