From c7b189a83fd1bb56427573f0806a8a3b9f0e4b48 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 19 Mar 2024 17:18:36 -0400 Subject: [PATCH] Begin implementing structures --- src/abstract_tree/type.rs | 25 +++++++------------------ src/parser.rs | 3 --- src/value.rs | 1 - 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/abstract_tree/type.rs b/src/abstract_tree/type.rs index d8d6181..793eb6c 100644 --- a/src/abstract_tree/type.rs +++ b/src/abstract_tree/type.rs @@ -12,7 +12,6 @@ use super::{AbstractTree, Action}; pub enum Type { Any, Boolean, - Custom(Identifier), Float, Function { parameter_types: Vec, @@ -26,6 +25,10 @@ pub enum Type { None, Range, String, + Structure { + name: Identifier, + fields: Vec<(Identifier, Type)>, + }, } impl Type { @@ -45,16 +48,6 @@ impl Type { | (Type::None, Type::None) | (Type::Range, Type::Range) | (Type::String, Type::String) => Ok(()), - (Type::Custom(left), Type::Custom(right)) => { - if left == right { - Ok(()) - } else { - Err(TypeConflict { - actual: other.clone(), - expected: self.clone(), - }) - } - } (Type::ListOf(left), Type::ListOf(right)) => { if let Ok(()) = left.check(right) { Ok(()) @@ -113,7 +106,6 @@ impl Display for Type { match self { Type::Any => write!(f, "any"), Type::Boolean => write!(f, "boolean"), - Type::Custom(name) => write!(f, "{name}"), Type::Float => write!(f, "float"), Type::Integer => write!(f, "integer"), Type::List => write!(f, "list"), @@ -147,6 +139,7 @@ impl Display for Type { write!(f, ") : {return_type}") } + Type::Structure { .. } => todo!(), } } } @@ -159,10 +152,6 @@ mod tests { fn check_same_types() { assert_eq!(Type::Any.check(&Type::Any), Ok(())); assert_eq!(Type::Boolean.check(&Type::Boolean), Ok(())); - assert_eq!( - Type::Custom(Identifier::new("foo")).check(&Type::Custom(Identifier::new("foo"))), - Ok(()) - ); assert_eq!(Type::Float.check(&Type::Float), Ok(())); assert_eq!(Type::Integer.check(&Type::Integer), Ok(())); assert_eq!(Type::List.check(&Type::List), Ok(())); @@ -183,8 +172,8 @@ mod tests { #[test] fn errors() { - let foo = Type::Custom(Identifier::new("foo")); - let bar = Type::Custom(Identifier::new("bar")); + let foo = Type::Integer; + let bar = Type::String; assert_eq!( foo.check(&bar), diff --git a/src/parser.rs b/src/parser.rs index 8e48f14..e49b82c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -101,9 +101,6 @@ pub fn parser<'src>() -> impl Parser< just(Token::Keyword("range")).to(Type::Range), just(Token::Keyword("str")).to(Type::String), just(Token::Keyword("list")).to(Type::List), - identifier - .clone() - .map(|identifier| Type::Custom(identifier)), )) }) .map_with(|r#type, state| r#type.with_position(state.span())); diff --git a/src/value.rs b/src/value.rs index 6fff84e..ae69c08 100644 --- a/src/value.rs +++ b/src/value.rs @@ -3,7 +3,6 @@ use std::{ collections::BTreeMap, fmt::{self, Display, Formatter}, io::stdin, - num::ParseIntError, ops::Range, sync::{Arc, OnceLock}, };