miden_assembly_syntax/ast/
form.rs1use alloc::{string::String, sync::Arc};
2
3use miden_debug_types::{SourceSpan, Span, Spanned};
4
5use super::{
6 AdviceMapEntry, Block, Constant, EnumType, Ident, ImportDecl, Item, Path, Procedure,
7 SubmoduleDecl, TypeAlias, TypeDecl,
8};
9
10#[derive(Debug, PartialEq, Eq)]
12pub enum Form {
13 ModuleDoc(Span<String>),
15 Doc(Span<String>),
17 Namespace(Span<Arc<Path>>),
21 ExternPackage(Ident),
25 Submodule(SubmoduleDecl),
27 Type(TypeAlias),
29 Enum(EnumType),
31 Constant(Constant),
33 Begin(Block),
35 Procedure(Procedure),
37 Import(ImportDecl),
39 AdviceMapEntry(AdviceMapEntry),
41}
42
43impl From<Span<String>> for Form {
44 fn from(doc: Span<String>) -> Self {
45 Self::Doc(doc)
46 }
47}
48
49impl From<SubmoduleDecl> for Form {
50 fn from(value: SubmoduleDecl) -> Self {
51 Self::Submodule(value)
52 }
53}
54
55impl From<TypeAlias> for Form {
56 fn from(value: TypeAlias) -> Self {
57 Self::Type(value)
58 }
59}
60
61impl From<EnumType> for Form {
62 fn from(value: EnumType) -> Self {
63 Self::Enum(value)
64 }
65}
66
67impl From<Constant> for Form {
68 fn from(constant: Constant) -> Self {
69 Self::Constant(constant)
70 }
71}
72
73impl From<ImportDecl> for Form {
74 fn from(import: ImportDecl) -> Self {
75 Self::Import(import)
76 }
77}
78
79impl From<Block> for Form {
80 fn from(block: Block) -> Self {
81 Self::Begin(block)
82 }
83}
84
85impl From<Item> for Form {
86 fn from(item: Item) -> Self {
87 match item {
88 Item::Constant(item) => Self::Constant(item),
89 Item::Type(TypeDecl::Alias(item)) => Self::Type(item),
90 Item::Type(TypeDecl::Enum(item)) => Self::Enum(item),
91 Item::Procedure(item) => Self::Procedure(item),
92 }
93 }
94}
95
96impl Spanned for Form {
97 fn span(&self) -> SourceSpan {
98 match self {
99 Self::Namespace(spanned) => spanned.span(),
100 Self::ExternPackage(spanned) => spanned.span(),
101 Self::Submodule(spanned) => spanned.name.span(),
102 Self::ModuleDoc(spanned) | Self::Doc(spanned) => spanned.span(),
103 Self::Type(spanned) => spanned.span(),
104 Self::Enum(spanned) => spanned.span(),
105 Self::Constant(Constant { span, .. })
106 | Self::AdviceMapEntry(AdviceMapEntry { span, .. }) => *span,
107 Self::Begin(spanned) => spanned.span(),
108 Self::Procedure(spanned) => spanned.span(),
109 Self::Import(spanned) => spanned.span(),
110 }
111 }
112}