1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
use crate::{
error::Error,
model::{
annotations::{Annotation, HasAnnotations},
check::Validate,
definitions::HasMembers,
identifiers::{Identifier, IdentifierReference},
members::Member,
modules::Module,
References, Span,
},
};
use std::{collections::HashSet, fmt::Debug};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
// ------------------------------------------------------------------------------------------------
// Public Macros
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// Public Types ❱ Type Definitions ❱ Structures
// ------------------------------------------------------------------------------------------------
/// Corresponds to the grammar rule `structure_def`.
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct StructureDef {
span: Option<Span>,
name: Identifier,
body: Option<StructureBody>,
}
/// Corresponds to the grammar rule `structure_body`.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct StructureBody {
span: Option<Span>,
annotations: Vec<Annotation>,
members: Vec<Member>,
}
// ------------------------------------------------------------------------------------------------
// Public Types ❱ Type Definitions ❱ Structures
// ------------------------------------------------------------------------------------------------
impl_has_name_for!(StructureDef);
impl_has_optional_body_for!(StructureDef, StructureBody);
impl_has_source_span_for!(StructureDef);
impl_references_for!(StructureDef => delegate optional body);
impl_validate_for!(StructureDef => delegate optional body, false, true);
impl_annotation_builder!(StructureDef, optional body);
impl StructureDef {
// --------------------------------------------------------------------------------------------
// Constructors
// --------------------------------------------------------------------------------------------
pub fn new(name: Identifier) -> Self {
Self {
span: None,
name,
body: None,
}
}
}
// ------------------------------------------------------------------------------------------------
impl_has_annotations_for!(StructureBody);
impl_has_members_for!(StructureBody);
impl_has_source_span_for!(StructureBody);
impl_validate_for_annotations_and_members!(StructureBody);
impl References for StructureBody {
fn referenced_types<'a>(&'a self, names: &mut HashSet<&'a IdentifierReference>) {
self.members().for_each(|m| m.referenced_types(names));
}
fn referenced_annotations<'a>(&'a self, names: &mut HashSet<&'a IdentifierReference>) {
self.members().for_each(|m| m.referenced_annotations(names));
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// Private Functions
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// Modules
// ------------------------------------------------------------------------------------------------