Fixing captures (#723)

* WIP fixing captures

* small fix

* WIP

* Rewrite to proof-of-concept better parse_def

* Add missing file

* Finish capture refactor

* Fix tests

* Add more tests
This commit is contained in:
JT
2022-01-12 15:06:56 +11:00
committed by GitHub
parent 47495715a6
commit 186da4d725
30 changed files with 424 additions and 164 deletions

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use nu_engine::{eval_block, CallExt};
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
engine::{CaptureBlock, Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value,
};
@ -79,11 +79,9 @@ fn with_env(
// let external_redirection = args.call_info.args.external_redirection;
let variable: Value = call.req(engine_state, stack, 0)?;
let block_id = call.positional[1]
.as_block()
.expect("internal error: expected block");
let block = engine_state.get_block(block_id).clone();
let mut stack = stack.collect_captures(&block.captures);
let capture_block: CaptureBlock = call.req(engine_state, stack, 1)?;
let block = engine_state.get_block(capture_block.block_id);
let mut stack = stack.captures_to_stack(&capture_block.captures);
let mut env: HashMap<String, Value> = HashMap::new();
@ -134,7 +132,7 @@ fn with_env(
stack.add_env_var(k, v);
}
eval_block(engine_state, &mut stack, &block, input)
eval_block(engine_state, &mut stack, block, input)
}
#[cfg(test)]