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