Skip to main content

microcad_lang_parse/ast/
mod.rs

1// Copyright © 2026 The µcad authors <info@microcad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4pub mod def;
5mod expression;
6mod literal;
7mod source;
8mod statement;
9mod ty;
10
11use microcad_lang_base::{Id, Span};
12
13pub use expression::*;
14pub use literal::*;
15pub use source::*;
16pub use statement::*;
17pub use ty::*;
18
19/// A µcad identifier
20#[derive(Debug, PartialEq, Hash, Eq)]
21#[allow(missing_docs)]
22pub struct Identifier {
23    pub span: Span,
24    pub name: Id,
25}
26
27impl Dummy for Identifier {
28    fn dummy(span: Span) -> Self {
29        Self {
30            span,
31            name: Id::default(),
32        }
33    }
34}
35
36/// A µcad program
37#[derive(Debug)]
38#[allow(missing_docs)]
39pub struct Program {
40    pub span: Span,
41    pub statements: StatementList,
42}
43
44/// Whitespace
45#[derive(Debug, Clone, PartialEq)]
46pub struct Whitespace(pub String);
47
48#[derive(Debug, Clone, PartialEq)]
49#[allow(missing_docs)]
50#[non_exhaustive]
51pub enum ItemExtra {
52    Comment(Comment),
53    Whitespace(Whitespace),
54}
55
56/// Non-syntactic extras that can be attached to many ast nodes
57#[derive(Clone, Debug, PartialEq, Default)]
58#[allow(missing_docs)]
59pub struct ItemExtras {
60    pub leading: LeadingExtras,
61    pub trailing: TrailingExtras,
62}
63
64/// Extras that occur *before* a syntax element.
65#[derive(Debug, Clone, PartialEq, Default)]
66#[allow(missing_docs)]
67pub struct TrailingExtras(pub Vec<ItemExtra>);
68
69/// Extras that occur *after* a syntax element.
70#[derive(Debug, Clone, PartialEq, Default)]
71#[allow(missing_docs)]
72pub struct LeadingExtras(pub Vec<ItemExtra>);
73
74/// Return a dummy of this syntax element.
75///
76/// Used for recovery.
77pub(crate) trait Dummy {
78    fn dummy(span: Span) -> Self;
79}