Rename module; Implement collection commands
This commit is contained in:
parent
26a71585f0
commit
350fbb701d
@ -59,7 +59,7 @@ impl Macro for String {
|
|||||||
identifier: "string",
|
identifier: "string",
|
||||||
description: "Stringify a value.",
|
description: "Stringify a value.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::Any],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,13 +89,13 @@ impl Macro for Count {
|
|||||||
identifier: "count",
|
identifier: "count",
|
||||||
description: "Return the number of items in a value.",
|
description: "Return the number of items in a value.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::Any],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, argument: &Value) -> Result<Value> {
|
fn run(&self, argument: &Value) -> Result<Value> {
|
||||||
let len = match argument {
|
let len = match argument {
|
||||||
Value::String(string) => string.len(),
|
Value::String(string) => string.chars().count(),
|
||||||
Value::List(list) => list.len(),
|
Value::List(list) => list.len(),
|
||||||
Value::Map(map) => map.len(),
|
Value::Map(map) => map.len(),
|
||||||
Value::Table(table) => table.len(),
|
Value::Table(table) => table.len(),
|
||||||
@ -119,7 +119,7 @@ impl Macro for CreateTable {
|
|||||||
identifier: "create_table",
|
identifier: "create_table",
|
||||||
description: "Define a new table with a list of column names and list of rows.",
|
description: "Define a new table with a list of column names and list of rows.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::ListOf(vec![ValueType::List, ValueType::List])],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ impl Macro for Rows {
|
|||||||
identifier: "rows",
|
identifier: "rows",
|
||||||
description: "Extract a table's rows as a list.",
|
description: "Extract a table's rows as a list.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::Table],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,13 +213,13 @@ impl Macro for Insert {
|
|||||||
identifier: "insert",
|
identifier: "insert",
|
||||||
description: "Add new rows to a table.",
|
description: "Add new rows to a table.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::Table, ValueType::List],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, argument: &Value) -> Result<Value> {
|
fn run(&self, argument: &Value) -> Result<Value> {
|
||||||
let argument = argument.as_list()?;
|
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();
|
let mut table = argument[0].as_table()?.clone();
|
||||||
|
|
||||||
table.reserve(new_rows.len());
|
table.reserve(new_rows.len());
|
||||||
@ -242,7 +242,7 @@ impl Macro for Select {
|
|||||||
identifier: "select",
|
identifier: "select",
|
||||||
description: "Extract one or more values based on their key.",
|
description: "Extract one or more values based on their key.",
|
||||||
group: "collections",
|
group: "collections",
|
||||||
inputs: vec![],
|
inputs: vec![ValueType::Table, ValueType::String],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,10 @@
|
|||||||
//! This module contains whale's built-in macro system. Every macro is listed
|
//! This module contains dust's built-in commands.
|
||||||
//! alphabetically. Use [call_macro] to check an identifier against every macro.
|
|
||||||
//!
|
//!
|
||||||
//! ## Writing macros
|
//! ## Writing macros
|
||||||
//!
|
//!
|
||||||
//! - snake case identifier, this is enforced by a test
|
//! - 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
|
//! - the description should be brief, it will display in the shell
|
||||||
//! - maintain alphabetical order
|
//!
|
||||||
//!
|
//!
|
||||||
//! ## Usage
|
//! ## Usage
|
||||||
//!
|
//!
|
@ -2,9 +2,9 @@
|
|||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
|
commands::*,
|
||||||
error::*,
|
error::*,
|
||||||
interface::*,
|
interface::*,
|
||||||
macros::*,
|
|
||||||
operator::Operator,
|
operator::Operator,
|
||||||
token::PartialToken,
|
token::PartialToken,
|
||||||
tree::Node,
|
tree::Node,
|
||||||
@ -14,9 +14,9 @@ pub use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mod commands;
|
||||||
mod error;
|
mod error;
|
||||||
mod interface;
|
mod interface;
|
||||||
mod macros;
|
|
||||||
mod operator;
|
mod operator;
|
||||||
mod token;
|
mod token;
|
||||||
mod tree;
|
mod tree;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
table = create_table (
|
table = create_table(
|
||||||
("text", "number", "bool"),
|
("text", "number", "bool"),
|
||||||
(
|
(
|
||||||
("a", 1, true),
|
("a", 1, true),
|
||||||
@ -7,7 +7,7 @@ table = create_table (
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
test_table = create_table (
|
test_table = create_table(
|
||||||
("text", "bool"),
|
("text", "bool"),
|
||||||
(
|
(
|
||||||
("a", true),
|
("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"),
|
("text", "number", "bool"),
|
||||||
(
|
(
|
||||||
("a", 1, true),
|
("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);
|
||||||
|
Loading…
Reference in New Issue
Block a user