diff --git a/src/macros/collections.rs b/src/commands/collections.rs similarity index 97% rename from src/macros/collections.rs rename to src/commands/collections.rs index f68d85c..53b2960 100644 --- a/src/macros/collections.rs +++ b/src/commands/collections.rs @@ -59,7 +59,7 @@ impl Macro for String { identifier: "string", description: "Stringify a value.", group: "collections", - inputs: vec![], + inputs: vec![ValueType::Any], } } @@ -89,13 +89,13 @@ impl Macro for Count { identifier: "count", description: "Return the number of items in a value.", group: "collections", - inputs: vec![], + inputs: vec![ValueType::Any], } } fn run(&self, argument: &Value) -> Result { let len = match argument { - Value::String(string) => string.len(), + Value::String(string) => string.chars().count(), Value::List(list) => list.len(), Value::Map(map) => map.len(), Value::Table(table) => table.len(), @@ -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![], + inputs: vec![ValueType::ListOf(vec![ValueType::List, ValueType::List])], } } @@ -155,7 +155,7 @@ impl Macro for Rows { identifier: "rows", description: "Extract a table's rows as a list.", group: "collections", - inputs: vec![], + inputs: vec![ValueType::Table], } } @@ -213,13 +213,13 @@ impl Macro for Insert { identifier: "insert", description: "Add new rows to a table.", group: "collections", - inputs: vec![], + inputs: vec![ValueType::Table, ValueType::List], } } fn run(&self, argument: &Value) -> Result { let argument = argument.as_list()?; - let new_rows = &argument[1..]; + let new_rows = argument[1].as_list()?; let mut table = argument[0].as_table()?.clone(); table.reserve(new_rows.len()); @@ -242,7 +242,7 @@ impl Macro for Select { identifier: "select", description: "Extract one or more values based on their key.", group: "collections", - inputs: vec![], + inputs: vec![ValueType::Table, ValueType::String], } } diff --git a/src/macros/command.rs b/src/commands/command.rs similarity index 100% rename from src/macros/command.rs rename to src/commands/command.rs diff --git a/src/macros/data_formats.rs b/src/commands/data_formats.rs similarity index 100% rename from src/macros/data_formats.rs rename to src/commands/data_formats.rs diff --git a/src/macros/disks.rs b/src/commands/disks.rs similarity index 100% rename from src/macros/disks.rs rename to src/commands/disks.rs diff --git a/src/macros/filesystem.rs b/src/commands/filesystem.rs similarity index 100% rename from src/macros/filesystem.rs rename to src/commands/filesystem.rs diff --git a/src/macros/general.rs b/src/commands/general.rs similarity index 100% rename from src/macros/general.rs rename to src/commands/general.rs diff --git a/src/macros/gui.rs b/src/commands/gui.rs similarity index 100% rename from src/macros/gui.rs rename to src/commands/gui.rs diff --git a/src/macros/logic.rs b/src/commands/logic.rs similarity index 100% rename from src/macros/logic.rs rename to src/commands/logic.rs diff --git a/src/macros/mod.rs b/src/commands/mod.rs similarity index 96% rename from src/macros/mod.rs rename to src/commands/mod.rs index 8c8bbbb..580b055 100644 --- a/src/macros/mod.rs +++ b/src/commands/mod.rs @@ -1,13 +1,10 @@ -//! This module contains whale's built-in macro system. Every macro is listed -//! alphabetically. Use [call_macro] to check an identifier against every macro. +//! This module contains dust's built-in commands. //! //! ## Writing macros //! //! - snake case identifier, this is enforced by a test -//! - the type name should be the identifier in upper camel case -//! - always verify user input, this creates helpful errors //! - the description should be brief, it will display in the shell -//! - maintain alphabetical order +//! //! //! ## Usage //! diff --git a/src/macros/network.rs b/src/commands/network.rs similarity index 100% rename from src/macros/network.rs rename to src/commands/network.rs diff --git a/src/macros/package_management.rs b/src/commands/package_management.rs similarity index 100% rename from src/macros/package_management.rs rename to src/commands/package_management.rs diff --git a/src/macros/random.rs b/src/commands/random.rs similarity index 100% rename from src/macros/random.rs rename to src/commands/random.rs diff --git a/src/macros/system.rs b/src/commands/system.rs similarity index 100% rename from src/macros/system.rs rename to src/commands/system.rs diff --git a/src/macros/time.rs b/src/commands/time.rs similarity index 100% rename from src/macros/time.rs rename to src/commands/time.rs diff --git a/src/lib.rs b/src/lib.rs index ccb5bd3..37fa1da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,9 @@ #![forbid(unsafe_code)] pub use crate::{ + commands::*, error::*, interface::*, - macros::*, operator::Operator, token::PartialToken, tree::Node, @@ -14,9 +14,9 @@ pub use crate::{ }, }; +mod commands; mod error; mod interface; -mod macros; mod operator; mod token; mod tree; diff --git a/tests/table.ds b/tests/table.ds index 25c3b5c..d9dfd24 100644 --- a/tests/table.ds +++ b/tests/table.ds @@ -1,4 +1,4 @@ -table = create_table ( +table = create_table( ("text", "number", "bool"), ( ("a", 1, true), @@ -7,7 +7,7 @@ table = create_table ( ) ); -test_table = create_table ( +test_table = create_table( ("text", "bool"), ( ("a", true), @@ -16,9 +16,9 @@ test_table = create_table ( ) ); -assert_equal(table:select("text", "bool"), test_table); +assert_equal(select(table, "text", "bool"), test_table); -test_table = create_table ( +test_table = create_table( ("text", "number", "bool"), ( ("a", 1, true), @@ -26,4 +26,4 @@ test_table = create_table ( ) ); -assert_equal(table:where('text == "a"'), test_table); +assert_equal(where(table, 'text == "a"'), test_table);