mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:24:58 +02:00
@ -27,6 +27,15 @@ impl<'s> Flatten<'s> {
|
||||
Expression::Block(block) => self.completion_locations(block),
|
||||
Expression::Invocation(block) => self.completion_locations(block),
|
||||
Expression::List(exprs) => exprs.iter().flat_map(|v| self.expression(v)).collect(),
|
||||
Expression::Table(headers, cells) => headers
|
||||
.iter()
|
||||
.flat_map(|v| self.expression(v))
|
||||
.chain(
|
||||
cells
|
||||
.iter()
|
||||
.flat_map(|v| v.iter().flat_map(|v| self.expression(v))),
|
||||
)
|
||||
.collect(),
|
||||
Expression::Command => vec![LocationType::Command.spanned(e.span)],
|
||||
Expression::Path(path) => self.expression(&path.head),
|
||||
Expression::Variable(_) => vec![LocationType::Variable.spanned(e.span)],
|
||||
|
@ -80,6 +80,46 @@ pub(crate) async fn evaluate_baseline_expr(
|
||||
|
||||
Ok(UntaggedValue::range(left, right).into_value(tag))
|
||||
}
|
||||
Expression::Table(headers, cells) => {
|
||||
let mut output_headers = vec![];
|
||||
|
||||
for expr in headers {
|
||||
let val = evaluate_baseline_expr(&expr, registry, it, vars, env).await?;
|
||||
|
||||
let header = val.as_string()?;
|
||||
output_headers.push(header);
|
||||
}
|
||||
|
||||
let mut output_table = vec![];
|
||||
|
||||
for row in cells {
|
||||
if row.len() != headers.len() {
|
||||
match (row.first(), row.last()) {
|
||||
(Some(first), Some(last)) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Cell count doesn't match header count",
|
||||
format!("expected {} columns", headers.len()),
|
||||
Span::new(first.span.start(), last.span.end()),
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
return Err(ShellError::untagged_runtime_error(
|
||||
"Cell count doesn't match header count",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut row_output = IndexMap::new();
|
||||
for cell in output_headers.iter().zip(row.iter()) {
|
||||
let val = evaluate_baseline_expr(&cell.1, registry, it, vars, env).await?;
|
||||
row_output.insert(cell.0.clone(), val);
|
||||
}
|
||||
output_table.push(UntaggedValue::row(row_output).into_value(tag.clone()));
|
||||
}
|
||||
|
||||
Ok(UntaggedValue::Table(output_table).into_value(tag))
|
||||
}
|
||||
Expression::List(list) => {
|
||||
let mut exprs = vec![];
|
||||
|
||||
|
Reference in New Issue
Block a user