1
0

Begin adding use statement

This commit is contained in:
Jeff 2024-07-01 10:40:36 -04:00
parent 1e7636903e
commit a79cb0b3e1
4 changed files with 53 additions and 2 deletions

View File

@ -17,6 +17,7 @@ pub mod structure_definition;
pub mod r#type; pub mod r#type;
pub mod type_alias; pub mod type_alias;
pub mod type_constructor; pub mod type_constructor;
pub mod r#use;
pub mod value_node; pub mod value_node;
pub mod r#while; pub mod r#while;
@ -45,6 +46,7 @@ pub use self::{
r#as::As, r#as::As,
r#loop::Loop, r#loop::Loop,
r#type::Type, r#type::Type,
r#use::Use,
r#while::While, r#while::While,
statement::Statement, statement::Statement,
structure_definition::StructureDefinition, structure_definition::StructureDefinition,

View File

@ -0,0 +1,48 @@
use std::{fs::read_to_string, path::Path};
use serde::{Deserialize, Serialize};
use crate::{
context::Context,
error::{RuntimeError, ValidationError},
lexer::{self, lex},
Type,
};
use super::{AbstractNode, Evaluation};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Use {
path: String,
}
impl AbstractNode for Use {
fn define_types(&self, context: &Context) -> Result<(), ValidationError> {
Ok(())
}
fn validate(&self, context: &Context, manage_memory: bool) -> Result<(), ValidationError> {
if Path::new(&self.path).exists() {
Ok(())
} else {
todo!()
}
}
fn evaluate(
self,
context: &Context,
manage_memory: bool,
) -> Result<Option<Evaluation>, RuntimeError> {
let file_contents = read_to_string(self.path)?;
let tokens = lex(&file_contents).map_err(|errors| RuntimeError::Use(errors))?;
let abstract_tree =
Ok(None)
}
fn expected_type(&self, context: &Context) -> Result<Option<Type>, ValidationError> {
todo!()
}
}

View File

@ -56,6 +56,7 @@ pub enum RuntimeError {
RwLockPoison(PoisonError), RwLockPoison(PoisonError),
ValidationFailure(ValidationError), ValidationFailure(ValidationError),
SerdeJson(serde_json::Error), SerdeJson(serde_json::Error),
Use(Vec<DustError>),
} }
impl From<PoisonError> for RuntimeError { impl From<PoisonError> for RuntimeError {

View File

@ -322,7 +322,7 @@ pub fn lexer<'src>() -> impl Parser<
none_of('\n') none_of('\n')
.repeated() .repeated()
.to_slice() .to_slice()
.map(|text: &str| Token::Use(text)), .map(|text: &str| Token::Use(text.trim())),
); );
choice(( choice((