diff --git a/src/commands/collections.rs b/src/commands/collections.rs index 5aa3272..43df7ed 100644 --- a/src/commands/collections.rs +++ b/src/commands/collections.rs @@ -10,7 +10,7 @@ impl Macro for Transform { identifier: "transform", description: "Alter a collection by calling a function on each value.", group: "collections", - inputs: vec![ValueType::ListOf(vec![ + inputs: vec![ValueType::ListExact(vec![ ValueType::List, ValueType::Function, ])], @@ -119,7 +119,7 @@ impl Macro for CreateTable { identifier: "create_table", description: "Define a new table with a list of column names and list of rows.", group: "collections", - inputs: vec![ValueType::ListOf(vec![ValueType::List, ValueType::List])], + inputs: vec![ValueType::ListExact(vec![ValueType::List, ValueType::List])], } } @@ -181,8 +181,8 @@ impl Macro for Get { description: "Retrieve a value from a collection.", group: "collections", inputs: vec![ - ValueType::ListOf(vec![ValueType::List, ValueType::Integer]), - ValueType::ListOf(vec![ValueType::Map, ValueType::String]), + ValueType::ListExact(vec![ValueType::List, ValueType::Integer]), + ValueType::ListExact(vec![ValueType::Map, ValueType::String]), ], } } @@ -242,7 +242,10 @@ impl Macro for Select { identifier: "select", description: "Extract one or more values based on their key.", group: "collections", - inputs: vec![ValueType::Table, ValueType::String], + inputs: vec![ValueType::ListExact(vec![ + ValueType::Table, + ValueType::ListOf(Box::new(ValueType::String)), + ])], } } diff --git a/src/commands/gui.rs b/src/commands/gui.rs index b293f69..319c761 100644 --- a/src/commands/gui.rs +++ b/src/commands/gui.rs @@ -232,7 +232,7 @@ impl GuiApp { } } - fn table_ui(&mut self, table: &Table, ui: &mut Ui) { + fn _table_ui(&mut self, table: &Table, ui: &mut Ui) { TableBuilder::new(ui) .resizable(true) .striped(true) diff --git a/src/commands/logic.rs b/src/commands/logic.rs index 4db05cd..819d43b 100644 --- a/src/commands/logic.rs +++ b/src/commands/logic.rs @@ -36,7 +36,7 @@ impl Macro for AssertEqual { identifier: "assert_equal", description: "Panic if two values do not match.", group: "test", - inputs: vec![ValueType::ListOf(vec![ValueType::Any, ValueType::Any])], + inputs: vec![ValueType::ListExact(vec![ValueType::Any, ValueType::Any])], } } @@ -61,11 +61,11 @@ impl Macro for If { description: "Evaluates the first argument. If true, it does the second argument.", group: "logic", inputs: vec![ - ValueType::ListOf(vec![ + ValueType::ListExact(vec![ ValueType::Boolean, ValueType::Any, ]), - ValueType::ListOf(vec![ + ValueType::ListExact(vec![ ValueType::Function, ValueType::Any, ])], @@ -99,12 +99,12 @@ impl Macro for IfElse { description: "Evaluates the first argument. If true, it does the second argument. If false, it does the third argument", group: "logic", inputs: vec![ - ValueType::ListOf(vec![ + ValueType::ListExact(vec![ ValueType::Boolean, ValueType::Any, ValueType::Any, ]), - ValueType::ListOf(vec![ + ValueType::ListExact(vec![ ValueType::Function, ValueType::Any, ValueType::Any, diff --git a/src/value/value_type.rs b/src/value/value_type.rs index ea2f4d4..36397bf 100644 --- a/src/value/value_type.rs +++ b/src/value/value_type.rs @@ -11,7 +11,8 @@ pub enum ValueType { Integer, Boolean, List, - ListOf(Vec), + ListOf(Box), + ListExact(Vec), Empty, Map, Table, @@ -30,9 +31,23 @@ impl PartialEq for ValueType { (ValueType::Float, ValueType::Float) => true, (ValueType::Integer, ValueType::Integer) => true, (ValueType::Boolean, ValueType::Boolean) => true, - (ValueType::ListOf(left), ValueType::ListOf(right)) => left == right, + (ValueType::ListExact(left), ValueType::ListExact(right)) => left == right, + (ValueType::ListExact(_), ValueType::List) => true, + (ValueType::List, ValueType::ListExact(_)) => true, (ValueType::ListOf(_), ValueType::List) => true, (ValueType::List, ValueType::ListOf(_)) => true, + (ValueType::ListOf(left), ValueType::ListOf(right)) => left == right, + (ValueType::ListOf(value_type), ValueType::ListExact(exact_list)) + | (ValueType::ListExact(exact_list), ValueType::ListOf(value_type)) => { + if exact_list + .iter() + .all(|exact_type| exact_type == value_type.as_ref()) + { + true + } else { + false + } + } (ValueType::List, ValueType::List) => true, (ValueType::Empty, ValueType::Empty) => true, (ValueType::Map, ValueType::Map) => true, @@ -53,8 +68,11 @@ impl Display for ValueType { ValueType::Integer => write!(f, "integer"), ValueType::Boolean => write!(f, "boolean"), ValueType::List => write!(f, "list"), - ValueType::ListOf(items) => { - let items = items + ValueType::ListOf(value_type) => { + write!(f, "list of {value_type}") + } + ValueType::ListExact(list) => { + let items = list .iter() .map(|value_type| value_type.to_string() + " ") .collect::(); @@ -78,7 +96,9 @@ impl From<&Value> for ValueType { Value::Integer(_) => ValueType::Integer, Value::Boolean(_) => ValueType::Boolean, Value::List(list) => { - ValueType::ListOf(list.iter().map(|value| value.value_type()).collect()) + let values = list.iter().map(|value| value.value_type()).collect(); + + ValueType::ListExact(values) } Value::Empty => ValueType::Empty, Value::Map(_) => ValueType::Map, diff --git a/tests/table.ds b/tests/table.ds index d9dfd24..65b75cc 100644 --- a/tests/table.ds +++ b/tests/table.ds @@ -16,7 +16,7 @@ test_table = create_table( ) ); -assert_equal(select(table, "text", "bool"), test_table); +assert_equal(select(table, ("text", "bool")), test_table); test_table = create_table( ("text", "number", "bool"),