Add cell paths for streams

This commit is contained in:
JT 2021-09-07 19:35:59 +12:00
parent 71bbd70a57
commit a8646f94ab
5 changed files with 29 additions and 12 deletions

View File

@ -30,7 +30,7 @@ impl Command for Each {
let context = context.clone();
match input {
Value::Range { val, .. } => Ok(Value::ValueStream {
Value::Range { val, .. } => Ok(Value::Stream {
stream: val
.into_iter()
.map(move |x| {
@ -52,7 +52,7 @@ impl Command for Each {
.into_value_stream(),
span: call.head,
}),
Value::List { vals: val, .. } => Ok(Value::ValueStream {
Value::List { vals: val, .. } => Ok(Value::Stream {
stream: val
.into_iter()
.map(move |x| {
@ -74,7 +74,7 @@ impl Command for Each {
.into_value_stream(),
span: call.head,
}),
Value::ValueStream { stream, .. } => Ok(Value::ValueStream {
Value::Stream { stream, .. } => Ok(Value::Stream {
stream: stream
.map(move |x| {
let engine_state = context.engine_state.borrow();

View File

@ -53,7 +53,7 @@ impl Command for For {
let context = context.clone();
match values {
Value::ValueStream { stream, .. } => Ok(Value::ValueStream {
Value::Stream { stream, .. } => Ok(Value::Stream {
stream: stream
.map(move |x| {
let engine_state = context.engine_state.borrow();

View File

@ -32,7 +32,7 @@ impl Command for Length {
span: call.head,
})
}
Value::ValueStream { stream, .. } => {
Value::Stream { stream, .. } => {
let length = stream.count();
Ok(Value::Int {

View File

@ -29,7 +29,7 @@ impl EvaluationContext {
// TODO: add ctrl-c support
let value = match value {
Value::ValueStream { stream, span } => Value::List {
Value::Stream { stream, span } => Value::List {
vals: stream.collect(),
span,
},

View File

@ -252,7 +252,7 @@ pub enum Value {
vals: Vec<Value>,
span: Span,
},
ValueStream {
Stream {
stream: ValueStream,
span: Span,
},
@ -290,7 +290,7 @@ impl Value {
Value::Record { span, .. } => *span,
Value::List { span, .. } => *span,
Value::Block { span, .. } => *span,
Value::ValueStream { span, .. } => *span,
Value::Stream { span, .. } => *span,
Value::Nothing { span, .. } => *span,
Value::Error { .. } => Span::unknown(),
}
@ -304,7 +304,7 @@ impl Value {
Value::Range { span, .. } => *span = new_span,
Value::String { span, .. } => *span = new_span,
Value::Record { span, .. } => *span = new_span,
Value::ValueStream { span, .. } => *span = new_span,
Value::Stream { span, .. } => *span = new_span,
Value::List { span, .. } => *span = new_span,
Value::Block { span, .. } => *span = new_span,
Value::Nothing { span, .. } => *span = new_span,
@ -327,7 +327,7 @@ impl Value {
Value::List { .. } => Type::List(Box::new(Type::Unknown)), // FIXME
Value::Nothing { .. } => Type::Nothing,
Value::Block { .. } => Type::Block,
Value::ValueStream { .. } => Type::ValueStream,
Value::Stream { .. } => Type::ValueStream,
Value::Error { .. } => Type::Error,
}
}
@ -357,7 +357,7 @@ impl Value {
)
}
Value::String { val, .. } => val,
Value::ValueStream { stream, .. } => stream.into_string(),
Value::Stream { stream, .. } => stream.into_string(),
Value::List { vals: val, .. } => format!(
"[{}]",
val.into_iter()
@ -404,7 +404,7 @@ impl Value {
return Err(ShellError::AccessBeyondEnd(val.len(), *origin_span));
}
}
Value::ValueStream { stream, .. } => {
Value::Stream { stream, .. } => {
if let Some(item) = stream.nth(*count) {
current = item;
} else {
@ -454,6 +454,23 @@ impl Value {
span: *span,
};
}
Value::Stream { stream, span } => {
let mut output = vec![];
for val in stream {
if let Value::Record { cols, vals, .. } = val {
for col in cols.iter().enumerate() {
if col.1 == column_name {
output.push(vals[col.0].clone());
}
}
}
}
current = Value::List {
vals: output,
span: *span,
};
}
x => {
return Err(ShellError::IncompatiblePathAccess(
format!("{}", x.get_type()),