use super::*;
use crate::helper::WrapDisplay;
mod builtin;
mod display;
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AnnotationNode {
pub documents: DocumentationList,
pub attributes: AttributeList,
pub modifiers: ModifierList,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ProceduralNode {
pub kind: AttributeKind,
pub path: NamePathNode,
pub arguments: ArgumentsList,
pub domain: Option<StatementBlock>,
pub span: Range<u32>,
}
impl From<ProceduralNode> for AttributeTerm {
fn from(node: ProceduralNode) -> Self {
AttributeTerm {
kind: node.kind,
path: node.path,
variant: vec![],
arguments: node.arguments,
domain: node.domain,
span: node.span,
}
}
}
impl ValkyrieNode for ProceduralNode {
fn get_range(&self) -> Range<usize> {
Range { start: self.span.start as usize, end: self.span.end as usize }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AttributeKind {
Normal,
Environment,
Script,
}
#[derive(Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AttributeList {
pub terms: Vec<AttributeTerm>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AttributeTerm {
pub kind: AttributeKind,
pub path: NamePathNode,
pub variant: Vec<IdentifierNode>,
pub arguments: ArgumentsList,
pub domain: Option<StatementBlock>,
pub span: Range<u32>,
}
#[derive(Clone, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ModifierList {
pub terms: Vec<IdentifierNode>,
}
impl ModifierList {
pub fn new(capacity: usize) -> Self {
Self { terms: Vec::with_capacity(capacity) }
}
}
impl Default for AttributeKind {
fn default() -> Self {
Self::Normal
}
}
impl Default for AnnotationNode {
fn default() -> Self {
Self { documents: Default::default(), attributes: Default::default(), modifiers: Default::default() }
}
}
impl AnnotationNode {
pub fn is_empty(&self) -> bool {
self.documents.is_empty() && self.attributes.is_empty() && self.modifiers.is_empty()
}
}
impl From<AttributeList> for AnnotationNode {
fn from(value: AttributeList) -> Self {
Self { documents: Default::default(), attributes: value, modifiers: Default::default() }
}
}
impl AttributeKind {
pub fn as_str(&self) -> &'static str {
match self {
Self::Normal => "#",
Self::Environment => "##",
Self::Script => "#!",
}
}
}
impl AttributeTerm {}
impl AttributeList {
pub fn new(capacity: usize) -> Self {
Self { terms: Vec::with_capacity(capacity) }
}
pub fn is_empty(&self) -> bool {
self.terms.is_empty()
}
}
impl ModifierList {
pub fn is_empty(&self) -> bool {
self.terms.is_empty()
}
pub fn contains(&self, modifier: &str) -> bool {
self.terms.iter().any(|x| x.name.eq(modifier))
}
}