Skip to main content

microcad_syntax/ast/
ty.rs

1// Copyright © 2026 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::Span;
5use crate::ast::Identifier;
6use compact_str::CompactString;
7
8/// The possible types
9#[derive(Debug, PartialEq)]
10#[allow(missing_docs)]
11pub enum Type {
12    Single(SingleType),
13    Array(ArrayType),
14    Tuple(TupleType),
15}
16
17impl Type {
18    /// Get the span of the type
19    pub fn span(&self) -> Span {
20        match self {
21            Type::Single(ty) => ty.span.clone(),
22            Type::Array(ty) => ty.span.clone(),
23            Type::Tuple(ty) => ty.span.clone(),
24        }
25    }
26}
27
28/// A type for a single numeric value
29#[derive(Debug, PartialEq)]
30#[allow(missing_docs)]
31pub struct SingleType {
32    pub span: Span,
33    pub name: CompactString,
34}
35
36/// An array type
37#[derive(Debug, PartialEq)]
38#[allow(missing_docs)]
39pub struct ArrayType {
40    pub span: Span,
41    pub inner: Box<Type>,
42}
43
44/// A tuple type
45#[derive(Debug, PartialEq)]
46#[allow(missing_docs)]
47pub struct TupleType {
48    pub span: Span,
49    pub inner: Vec<(Option<Identifier>, Type)>,
50}