Skip to main content

microcad_syntax/ast/
ty.rs

1// Copyright © 2026 The µcad authors <info@microcad.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    pub(crate) fn dummy(span: Span) -> Self {
28        Type::Single(SingleType {
29            span,
30            name: CompactString::default(),
31        })
32    }
33}
34
35/// A type for a single numeric value
36#[derive(Debug, PartialEq)]
37#[allow(missing_docs)]
38pub struct SingleType {
39    pub span: Span,
40    pub name: CompactString,
41}
42
43/// An array type
44#[derive(Debug, PartialEq)]
45#[allow(missing_docs)]
46pub struct ArrayType {
47    pub span: Span,
48    pub inner: Box<Type>,
49}
50
51/// A tuple type
52#[derive(Debug, PartialEq)]
53#[allow(missing_docs)]
54pub struct TupleType {
55    pub span: Span,
56    pub inner: Vec<(Option<Identifier>, Type)>,
57}