Skip to main content

microcad_lang_parse/ast/
ty.rs

1// Copyright © 2026 The µcad authors <info@microcad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::ast;
5
6use microcad_lang_base::{Id, Span};
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
28impl ast::Dummy for Type {
29    fn dummy(span: Span) -> Self {
30        Type::Single(SingleType {
31            span,
32            name: Id::default(),
33        })
34    }
35}
36
37/// A type for a single numeric value
38#[derive(Debug, PartialEq)]
39#[allow(missing_docs)]
40pub struct SingleType {
41    pub span: Span,
42    pub name: Id,
43}
44
45/// An array type
46#[derive(Debug, PartialEq)]
47#[allow(missing_docs)]
48pub struct ArrayType {
49    pub span: Span,
50    pub inner: Box<Type>,
51}
52
53/// A tuple type
54#[derive(Debug, PartialEq)]
55#[allow(missing_docs)]
56pub struct TupleType {
57    pub span: Span,
58    pub inner: Vec<(Option<ast::Identifier>, Type)>,
59}
60
61/// A µcad unit: mm, m³, %.
62#[derive(Debug, PartialEq, Hash, Eq)]
63#[allow(missing_docs)]
64pub struct Unit {
65    pub span: Span,
66    pub name: Id,
67}