microcad_lang_parse/ast/
ty.rs1use crate::ast;
5
6use microcad_lang_base::{Id, Span};
7
8#[derive(Debug, PartialEq)]
10#[allow(missing_docs)]
11pub enum Type {
12 Single(SingleType),
13 Array(ArrayType),
14 Tuple(TupleType),
15}
16
17impl Type {
18 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#[derive(Debug, PartialEq)]
39#[allow(missing_docs)]
40pub struct SingleType {
41 pub span: Span,
42 pub name: Id,
43}
44
45#[derive(Debug, PartialEq)]
47#[allow(missing_docs)]
48pub struct ArrayType {
49 pub span: Span,
50 pub inner: Box<Type>,
51}
52
53#[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#[derive(Debug, PartialEq, Hash, Eq)]
63#[allow(missing_docs)]
64pub struct Unit {
65 pub span: Span,
66 pub name: Id,
67}