miden_assembly/ast/
form.rs1use alloc::string::String;
2
3use super::{Block, Constant, Export, Import};
4use crate::{SourceSpan, Span, Spanned};
5
6#[derive(Debug, PartialEq, Eq)]
8pub enum Form {
9 ModuleDoc(Span<String>),
11 Doc(Span<String>),
13 Import(Import),
15 Constant(Constant),
17 Begin(Block),
19 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}