use super::*;
mod display;
mod iters;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ClassKind {
Class,
Structure,
}
#[doc = include_str!("readme.md")]
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClassDeclaration {
pub name: IdentifierNode,
pub kind: ClassKind,
pub annotations: AnnotationNode,
pub generic: Option<ParametersList>,
pub inherits: Option<String>,
pub implements: Vec<String>,
pub terms: Vec<ClassTerm>,
pub span: Range<u32>,
}
impl Debug for ClassDeclaration {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let w = &mut match self.kind {
ClassKind::Class => f.debug_struct("DefineClass"),
ClassKind::Structure => f.debug_struct("DefineStructure"),
};
if !self.annotations.is_empty() {
w.field("annotations", &self.annotations);
}
w.field("name", &WrapDisplay::new(&self.name));
if let Some(s) = &self.generic {
w.field("generic", s);
}
if let Some(s) = &self.inherits {
w.field("inherits", s);
}
if !self.implements.is_empty() {
w.field("implements", &self.implements);
}
if !self.terms.is_empty() {
w.field("terms", &self.terms);
}
w.field("span", &self.span);
w.finish()
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ClassTerm {
Macro(ProceduralNode),
Field(FieldDeclaration),
Method(MethodDeclaration),
Domain(DomainDeclaration),
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConstructObjectNode {
pub base_classes: Option<String>,
pub bounds: Option<ExpressionKind>,
pub span: Range<u32>,
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldDeclaration {
pub name: IdentifierNode,
pub annotations: AnnotationNode,
pub typing: Option<ExpressionKind>,
pub default: Option<ExpressionKind>,
pub span: Range<u32>,
}
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MethodDeclaration {
pub name: NamePathNode,
pub annotations: AnnotationNode,
pub generics: ParametersList,
pub parameters: ParametersList,
pub returns: FunctionReturnNode,
pub body: Option<StatementBlock>,
pub span: Range<u32>,
}
impl Debug for MethodDeclaration {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let w = &mut f.debug_struct("Method");
if !self.annotations.is_empty() {
w.field("annotations", &self.annotations);
}
w.field("name", &WrapDisplay::new(&self.name));
if !self.generics.terms.is_empty() {
w.field("generics", &self.generics);
}
if !self.parameters.terms.is_empty() {
w.field("parameters", &self.parameters);
}
if let Some(s) = &self.returns.typing {
w.field("returns", s);
}
if let Some(s) = &self.body {
w.field("body", s);
}
w.field("span", &self.span);
w.finish()
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DomainDeclaration {
pub annotations: AnnotationNode,
pub body: Vec<ClassTerm>,
pub span: Range<u32>,
}
impl ValkyrieNode for ConstructObjectNode {
fn get_range(&self) -> Range<usize> {
Range { start: self.span.start as usize, end: self.span.end as usize }
}
}