miden_assembly_syntax/ast/
form.rs

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