Split blocks and closures (#7075)

* Split closures and blocks

* Tests mostly working

* finish last fixes, passes all tests

* fmt
This commit is contained in:
JT
2022-11-10 21:21:49 +13:00
committed by GitHub
parent 921a66554e
commit 63433f1bc8
57 changed files with 576 additions and 220 deletions

View File

@ -125,7 +125,7 @@ pub fn value_to_json_value(v: &Value) -> Result<nu_json::Value, ShellError> {
Value::List { vals, .. } => nu_json::Value::Array(json_list(vals)?),
Value::Error { error } => return Err(error.clone()),
Value::Block { .. } | Value::Range { .. } => nu_json::Value::Null,
Value::Closure { .. } | Value::Block { .. } | Value::Range { .. } => nu_json::Value::Null,
Value::Binary { val, .. } => {
nu_json::Value::Array(val.iter().map(|x| nu_json::Value::U64(*x as u64)).collect())
}

View File

@ -66,6 +66,10 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
"block not supported".into(),
span,
)),
Value::Closure { .. } => Err(ShellError::UnsupportedInput(
"closure not supported".into(),
span,
)),
Value::Bool { val, .. } => {
if *val {
Ok("true".to_string())

View File

@ -100,6 +100,7 @@ fn local_into_string(value: Value, separator: &str, config: &Config) -> String {
.collect::<Vec<_>>()
.join(separator),
Value::Block { val, .. } => format!("<Block {}>", val),
Value::Closure { val, .. } => format!("<Closure {}>", val),
Value::Nothing { .. } => String::new(),
Value::Error { error } => format!("{:?}", error),
Value::Binary { val, .. } => format!("{:?}", val),

View File

@ -67,6 +67,11 @@ fn helper(engine_state: &EngineState, v: &Value) -> Result<toml::Value, ShellErr
let code = String::from_utf8_lossy(code).to_string();
toml::Value::String(code)
}
Value::Closure { span, .. } => {
let code = engine_state.get_span_contents(span);
let code = String::from_utf8_lossy(code).to_string();
toml::Value::String(code)
}
Value::Nothing { .. } => toml::Value::String("<Nothing>".to_string()),
Value::Error { error } => return Err(error.clone()),
Value::Binary { val, .. } => toml::Value::Array(

View File

@ -72,6 +72,7 @@ pub fn value_to_yaml_value(v: &Value) -> Result<serde_yaml::Value, ShellError> {
serde_yaml::Value::Sequence(out)
}
Value::Block { .. } => serde_yaml::Value::Null,
Value::Closure { .. } => serde_yaml::Value::Null,
Value::Nothing { .. } => serde_yaml::Value::Null,
Value::Error { error } => return Err(error.clone()),
Value::Binary { val, .. } => serde_yaml::Value::Sequence(