mago-type-syntax 1.7.0

Provides core utilities useful for building lexers and parsers within Mago.
Documentation
use serde::Serialize;

use mago_span::HasSpan;
use mago_span::Span;

use crate::ast::Type;

#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, PartialOrd, Ord)]
pub struct SliceType<'input> {
    pub inner: Box<Type<'input>>,
    pub left_bracket: Span,
    pub right_bracket: Span,
}

impl HasSpan for SliceType<'_> {
    fn span(&self) -> Span {
        self.inner.span().join(self.right_bracket)
    }
}

impl std::fmt::Display for SliceType<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}[]", self.inner)
    }
}