1
0

Implement colu

This commit is contained in:
Jeff 2023-10-22 16:32:55 -04:00
parent d527b3c9c0
commit c6ef9ad57f
5 changed files with 3200 additions and 3086 deletions

View File

@ -47,6 +47,10 @@ pub enum Tool {
RandomBoolean,
RandomInteger,
RandomFloat,
// Random
Columns(Expression),
Rows(Expression),
}
impl AbstractTree for Tool {
@ -203,6 +207,18 @@ impl AbstractTree for Tool {
"random_boolean" => Tool::RandomBoolean,
"random_float" => Tool::RandomFloat,
"random_integer" => Tool::RandomInteger,
"columns" => {
let expression_node = node.child(2).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?;
Tool::Columns(expression)
}
"rows" => {
let expression_node = node.child(2).unwrap();
let expression = Expression::from_syntax_node(source, expression_node)?;
Tool::Rows(expression)
}
_ => {
return Err(Error::UnexpectedSyntaxNode {
expected: "built-in tool",
@ -486,6 +502,30 @@ impl AbstractTree for Tool {
Tool::RandomBoolean => Ok(Value::Boolean(random())),
Tool::RandomFloat => Ok(Value::Float(random())),
Tool::RandomInteger => Ok(Value::Integer(random())),
Tool::Columns(expression) => {
let column_names = expression
.run(source, context)?
.as_table()?
.headers()
.iter()
.cloned()
.map(|column_name| Value::String(column_name))
.collect();
Ok(Value::List(column_names))
}
Tool::Rows(expression) => {
let rows = expression
.run(source, context)?
.as_table()?
.rows()
.iter()
.cloned()
.map(|row| Value::List(row))
.collect();
Ok(Value::List(rows))
}
}
}
}

View File

@ -293,6 +293,10 @@ module.exports = grammar({
'random_boolean',
'random_float',
'random_integer',
// Tables
'rows',
'columns',
),
}
});

View File

@ -1165,6 +1165,14 @@
{
"type": "STRING",
"value": "random_integer"
},
{
"type": "STRING",
"value": "rows"
},
{
"type": "STRING",
"value": "columns"
}
]
}

View File

@ -729,6 +729,10 @@
"type": "bash",
"named": false
},
{
"type": "columns",
"named": false
},
{
"type": "else",
"named": false
@ -849,6 +853,10 @@
"type": "remove",
"named": false
},
{
"type": "rows",
"named": false
},
{
"type": "select",
"named": false

File diff suppressed because it is too large Load Diff