use alloc::string::String;
use super::{Block, Constant, Export, Import};
use crate::{SourceSpan, Span, Spanned};
#[derive(Debug, PartialEq, Eq)]
pub enum Form {
ModuleDoc(Span<String>),
Doc(Span<String>),
Import(Import),
Constant(Constant),
Begin(Block),
Procedure(Export),
}
impl From<Span<String>> for Form {
fn from(doc: Span<String>) -> Self {
Self::Doc(doc)
}
}
impl From<Import> for Form {
fn from(import: Import) -> Self {
Self::Import(import)
}
}
impl From<Constant> for Form {
fn from(constant: Constant) -> Self {
Self::Constant(constant)
}
}
impl From<Block> for Form {
fn from(block: Block) -> Self {
Self::Begin(block)
}
}
impl From<Export> for Form {
fn from(export: Export) -> Self {
Self::Procedure(export)
}
}
impl Spanned for Form {
fn span(&self) -> SourceSpan {
match self {
Self::ModuleDoc(spanned) | Self::Doc(spanned) => spanned.span(),
Self::Import(Import { span, .. }) | Self::Constant(Constant { span, .. }) => *span,
Self::Begin(spanned) => spanned.span(),
Self::Procedure(spanned) => spanned.span(),
}
}
}