use super::*;
use crate::{ExpressionBody, StringLiteralNode, StringTextNode};
mod display;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StatementNode {
pub r#type: StatementBody,
pub end_semicolon: bool,
pub span: Range<u32>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, From)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum StatementBody {
Nothing,
Document(Box<DocumentationNode>),
Annotation(Box<AnnotationList>),
Namespace(Box<NamespaceDeclaration>),
Import(Box<ImportStatement>),
Class(Box<ClassDeclaration>),
ClassField(Box<ClassFieldDeclaration>),
ClassMethod(Box<ClassMethodDeclaration>),
Union(Box<UnionDeclaration>),
UnionField(Box<UnionFieldDeclaration>),
Enumerate(Box<EnumerateDeclaration>),
EnumerateField(Box<EnumerateFieldDeclaration>),
Flags(Box<FlagsDeclaration>),
Tagged(Box<TaggedDeclaration>),
Variant(Box<VariantDeclaration>),
Function(Box<FunctionDeclaration>),
While(Box<WhileLoop>),
For(Box<ForLoop>),
LetBind(Box<LetBindNode>),
Guard(Box<GuardStatement>),
Control(Box<ControlNode>),
Expression(Box<ExpressionNode>),
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StatementContext {}
impl From<AnnotationNode> for StatementBody {
fn from(value: AnnotationNode) -> Self {
let list = AnnotationList { kind: value.kind, terms: vec![value.term], span: value.span };
StatementBody::Annotation(Box::new(list))
}
}
impl StatementNode {
pub fn expression(body: ExpressionBody, span: Range<u32>) -> Self {
Self {
r#type: StatementBody::Expression(Box::new(ExpressionNode { type_level: false, body, span: span.clone() })),
end_semicolon: false,
span: span.clone(),
}
}
pub fn text<S: ToString>(s: S, span: Range<u32>) -> Self {
let literal = StringTextNode { text: s.to_string(), span: span.clone() };
Self::expression(ExpressionBody::Text(Box::new(literal)), span)
}
pub fn string<S: ToString>(s: S, span: Range<u32>) -> Self {
let literal = StringLiteralNode { raw: s.to_string(), unit: None, span: span.clone() };
Self::expression(ExpressionBody::String(Box::new(literal)), span)
}
}