miden_assembly/ast/
form.rs

1use alloc::string::String;
2
3use super::{Block, Constant, Export, Import};
4use crate::{SourceSpan, Span, Spanned};
5
6/// This type represents the top-level forms of a Miden Assembly module
7#[derive(Debug, PartialEq, Eq)]
8pub enum Form {
9    /// A documentation string for the entire module
10    ModuleDoc(Span<String>),
11    /// A documentation string
12    Doc(Span<String>),
13    /// An import from another module
14    Import(Import),
15    /// A constant definition, possibly unresolved
16    Constant(Constant),
17    /// An executable block, represents a program entrypoint
18    Begin(Block),
19    /// A procedure
20    Procedure(Export),
21}
22
23impl From<Span<String>> for Form {
24    fn from(doc: Span<String>) -> Self {
25        Self::Doc(doc)
26    }
27}
28
29impl From<Import> for Form {
30    fn from(import: Import) -> Self {
31        Self::Import(import)
32    }
33}
34
35impl From<Constant> for Form {
36    fn from(constant: Constant) -> Self {
37        Self::Constant(constant)
38    }
39}
40
41impl From<Block> for Form {
42    fn from(block: Block) -> Self {
43        Self::Begin(block)
44    }
45}
46
47impl From<Export> for Form {
48    fn from(export: Export) -> Self {
49        Self::Procedure(export)
50    }
51}
52
53impl Spanned for Form {
54    fn span(&self) -> SourceSpan {
55        match self {
56            Self::ModuleDoc(spanned) | Self::Doc(spanned) => spanned.span(),
57            Self::Import(Import { span, .. }) | Self::Constant(Constant { span, .. }) => *span,
58            Self::Begin(spanned) => spanned.span(),
59            Self::Procedure(spanned) => spanned.span(),
60        }
61    }
62}