From 350fbb701d45d2bab80016267999c9577f31937d Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 23 Aug 2023 01:21:02 -0400 Subject: [PATCH] Rename module; Implement collection commands --- src/{macros => commands}/collections.rs | 16 ++++++++-------- src/{macros => commands}/command.rs | 0 src/{macros => commands}/data_formats.rs | 0 src/{macros => commands}/disks.rs | 0 src/{macros => commands}/filesystem.rs | 0 src/{macros => commands}/general.rs | 0 src/{macros => commands}/gui.rs | 0 src/{macros => commands}/logic.rs | 0 src/{macros => commands}/mod.rs | 7 ++----- src/{macros => commands}/network.rs | 0 src/{macros => commands}/package_management.rs | 0 src/{macros => commands}/random.rs | 0 src/{macros => commands}/system.rs | 0 src/{macros => commands}/time.rs | 0 src/lib.rs | 4 ++-- tests/table.ds | 10 +++++----- 16 files changed, 17 insertions(+), 20 deletions(-) rename src/{macros => commands}/collections.rs (97%) rename src/{macros => commands}/command.rs (100%) rename src/{macros => commands}/data_formats.rs (100%) rename src/{macros => commands}/disks.rs (100%) rename src/{macros => commands}/filesystem.rs (100%) rename src/{macros => commands}/general.rs (100%) rename src/{macros => commands}/gui.rs (100%) rename src/{macros => commands}/logic.rs (100%) rename src/{macros => commands}/mod.rs (96%) rename src/{macros => commands}/network.rs (100%) rename src/{macros => commands}/package_management.rs (100%) rename src/{macros => commands}/random.rs (100%) rename src/{macros => commands}/system.rs (100%) rename src/{macros => commands}/time.rs (100%) 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);