1
0
dust/dust-lang/src/abstract_tree/structure_definition.rs

43 lines
1.0 KiB
Rust
Raw Normal View History

2024-06-04 18:47:15 +00:00
use serde::{Deserialize, Serialize};
2024-03-19 21:49:24 +00:00
use crate::{
context::Context,
error::{RuntimeError, ValidationError},
2024-03-25 04:16:55 +00:00
identifier::Identifier,
2024-03-19 21:49:24 +00:00
};
2024-03-25 04:16:55 +00:00
use super::{AbstractNode, Action, Type, WithPosition};
2024-03-19 21:49:24 +00:00
2024-06-04 18:47:15 +00:00
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
2024-03-19 21:49:24 +00:00
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 }
}
}
impl AbstractNode for StructureDefinition {
2024-04-22 12:25:20 +00:00
fn validate(
&self,
_context: &mut Context,
_manage_memory: bool,
) -> Result<(), ValidationError> {
2024-03-19 21:49:24 +00:00
Ok(())
}
2024-04-22 11:56:03 +00:00
fn run(self, context: &mut Context, _manage_memory: bool) -> Result<Action, RuntimeError> {
2024-03-19 21:49:24 +00:00
let struct_type = Type::Structure {
name: self.name.clone(),
fields: self.fields,
};
context.set_type(self.name, struct_type)?;
Ok(Action::None)
}
}