2024-03-19 21:49:24 +00:00
|
|
|
use crate::{
|
|
|
|
context::Context,
|
|
|
|
error::{RuntimeError, ValidationError},
|
|
|
|
};
|
|
|
|
|
2024-03-20 04:28:28 +00:00
|
|
|
use super::{AbstractNode, Action, Identifier, Type, WithPosition};
|
2024-03-19 21:49:24 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
|
|
|
pub struct StructureDefinition {
|
|
|
|
name: Identifier,
|
|
|
|
fields: Vec<(Identifier, WithPosition<Type>)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StructureDefinition {
|
|
|
|
pub fn new(name: Identifier, fields: Vec<(Identifier, WithPosition<Type>)>) -> Self {
|
|
|
|
Self { name, fields }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-20 04:28:28 +00:00
|
|
|
impl AbstractNode for StructureDefinition {
|
2024-03-19 21:49:24 +00:00
|
|
|
fn expected_type(&self, _context: &Context) -> Result<Type, ValidationError> {
|
|
|
|
Ok(Type::None)
|
|
|
|
}
|
|
|
|
|
2024-03-20 04:28:28 +00:00
|
|
|
fn validate(&self, _context: &Context) -> Result<(), ValidationError> {
|
2024-03-19 21:49:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, context: &Context) -> Result<Action, RuntimeError> {
|
|
|
|
let struct_type = Type::Structure {
|
|
|
|
name: self.name.clone(),
|
|
|
|
fields: self.fields,
|
|
|
|
};
|
|
|
|
|
|
|
|
context.set_type(self.name, struct_type)?;
|
|
|
|
|
|
|
|
Ok(Action::None)
|
|
|
|
}
|
|
|
|
}
|